SpringBoot切換版本時項目訪問不到thymeleaf頁面404

由IDEA選擇的版本2.1.16切換成1.5.10版本時,發現在項目正常啓動時跳轉themeleaf頁面訪問不到,報404。

 

查看控制報錯日誌:

 

發現是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中的一些標籤不起作用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章