由IDEA选择的版本2.1.16切换成1.5.10版本时,发现在项目正常启动时跳转themeleaf页面访问不到,报404。
image
查看控制报错日志:
image
发现是html文件解析错误 SpringBoot中thymeleaf的默认版本为:1.5.10.RELEAS
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
第一种办法就是加上结束标签。
第二种办法就是在pom.xml中的 properties 中指明Thymeleaf标签的版本号即可。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--添加如下两行代码指定Thymeleaf标签的版本-->
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
</properties>
第三种办法是在pom.xml中添加依赖。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
application.properties中:
spring.thymeleaf.mode=LEGACYHTML5
推荐使用方法三。
注意:第二种办法可能在springsecurity中的一些标签不起作用。