# spring-boot-demo-template-thymeleaf > 本 demo 主要演示了 Spring Boot 项目如何集成 thymeleaf 模板引擎 ## pom.xml ```xml 4.0.0 spring-boot-demo-template-thymeleaf 1.0.0-SNAPSHOT jar spring-boot-demo-template-thymeleaf Demo project for Spring Boot com.xkcoding spring-boot-demo 1.0.0-SNAPSHOT UTF-8 UTF-8 1.8 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.projectlombok lombok true cn.hutool hutool-all spring-boot-demo-template-thymeleaf org.springframework.boot spring-boot-maven-plugin ``` ## IndexController.java ```java /** *

* 主页 *

* * @author yangkai.shen * @date Created in 2018-10-10 10:12 */ @Controller @Slf4j public class IndexController { @GetMapping(value = {"", "/"}) public ModelAndView index(HttpServletRequest request) { ModelAndView mv = new ModelAndView(); User user = (User) request.getSession().getAttribute("user"); if (ObjectUtil.isNull(user)) { mv.setViewName("redirect:/user/login"); } else { mv.setViewName("page/index"); mv.addObject(user); } return mv; } } ``` ## UserController.java ```java /** *

* 用户页面 *

* * @author yangkai.shen * @date Created in 2018-10-10 10:11 */ @Controller @RequestMapping("/user") @Slf4j public class UserController { @PostMapping("/login") public ModelAndView login(User user, HttpServletRequest request) { ModelAndView mv = new ModelAndView(); mv.addObject(user); mv.setViewName("redirect:/"); request.getSession().setAttribute("user", user); return mv; } @GetMapping("/login") public ModelAndView login() { return new ModelAndView("page/login"); } } ``` ## index.html ```jsp
欢迎登录,
``` ## login.html ```jsp
用户名 密码
``` ## application.yml ```yaml server: port: 8080 servlet: context-path: /demo spring: thymeleaf: mode: HTML encoding: UTF-8 servlet: content-type: text/html cache: false ``` ## Thymeleaf语法糖学习文档 https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html