1. pom.xml
<!--整合thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2. yml
spring: thymeleaf: prefix: classpath:/templates/ check-template-location: true suffix: .html encoding: utf-8 servlet: content-type: text/html mode: HTML5 cache: false
3.Controller层 LoginController
@Controller public class LoginController { @GetMapping("/login") public String toLogin(Model model){ model.addAttribute("name","sunrui"); return "login"; } }
4. login.html
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <p th:text=" 'hello,' + ${name} + '!' "/> </body> </html>