Spring Boot Thymeleaf 解析出錯

 緣由就是Spring Boot 默認依賴的是低版本的Thymeleaf,低版本的Thymeleaf不能解析HTML5格式的HTML代碼,而是把HTML當成XML解析,全部標籤必須閉合!
 可是!我試過把標籤都閉合以後仍是會報錯,並且每一個標籤都閉合實在是很繁瑣的過程,就另尋解決方案了。最後在Github中下載了一份源碼(Github源碼地址)。查看源碼後,找到解決方法以下:
pom.xml中的properties標籤中加入以下代碼java

<!-- 覆蓋thymeleaf版本依賴 -->
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>

 這段代碼是將Spring Boot 默認依賴的thymeleaf版本替換爲咱們定義的版本,這裏爲3.0.2.RELEASE。 3.x 以上的 thymeleaf 已經支持HTML5格式HTML代碼解析,報錯的問題就解決了!git

相關文章
相關標籤/搜索