springboot使用thymeleaf ,以及使用手冊

一:在使用springboot的過程中,如果使用thymeleaf作爲模板文件
則要求HTML格式必須爲嚴格的html5格式,必須有結束標籤,否則會報錯!解決辦法如下:

  1、你可以使用嚴格的標籤,也就是每個標籤都有結束標籤,這種可能比較麻煩
  2、在application.properties中增加

spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

或者:
spring:
  thymeleaf:
    content-type: text/html
    #開發時關閉緩存,不然沒法看到實時頁面
    cache: false
    enabled: true
    prefix: classpath:/templates/
    encoding: UTF-8
    mode: LEGACYHTML5
    suffix: .html

pom.xml中添加依賴如下

<!--所需依賴-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<!--去除HTML 嚴格規範-->
<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
    <version>1.9.22</version>
</dependency>

 

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