pom文件引入依赖

<!--引入thymeleaf的依赖-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

.properties

# 默认路径,前后缀
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
# 模板格式
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=true

如果出现:

org.xml.sax.SAXParseException: The element type "meta" must be terminated by the matching end-tag "</meta>".

是因为spring-boot-starter-thymeleaf对html5默认校验要求高。一言不合就报错
解决方案:
1、在pom.xml中添加依赖

<!--启用不严格检查html-->
<dependency>
   <groupId>net.sourceforge.nekohtml</groupId>
   <artifactId>nekohtml</artifactId>
   <version>1.9.22</version>
</dependency>

2、在 application.properties
2.1、关闭缓存

 spring.thymeleaf.cache=false

2.2、修改

spring.thymeleaf.mode=LEGACYHTML5
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐