<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、设置thymeleaf版本,版本3检查html标签可以没有闭合结束符
<properties>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version>
</properties>
spring.thymeleaf.cache=false spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html spring.thymeleaf.mode=HTML5
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <title>Hello World!</title> </head> <body> <h1 th:inline="text">Hello</h1> <p th:text="${hello}"></p> </body> </html>
@RequestMapping @Controller public class IndexController { @GetMapping("/helloHtml") public String testHelloHtml(Model model){ model.addAttribute("hello", "你好"); return "index"; } }
原文:https://www.cnblogs.com/moris5013/p/11492716.html