SpringBoot切换版本时项目访问不到thymeleaf页面404

由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中的一些标签不起作用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值