解決thymeleaf模板嚴格要求格式
阿新 • • 發佈:2018-12-26
引入依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/net.sourceforge.nekohtml/nekohtml --> <dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> <version>1.9.22</version> </dependency>
application.prpoerties加入配置
###Thymeleaf配置
spring.thymeleaf.prefix=classpath:/view/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
首先關閉快取
spring.thymeleaf.cache=false
設定模板格式為
spring.thymeleaf.mode=HTML5
在HTML頁面的HTML標籤里加入
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title >Title</title> </head> <body> <div th:text="${session.username}">liubei</div> <input type="text"> <img src="#"> <img src="#"> </body> </html>