1. 程式人生 > >解決:org.xml.sax.SAXParseException: 元素型別 "head" 必須由匹配的結束標記 "</head>問題

解決:org.xml.sax.SAXParseException: 元素型別 "head" 必須由匹配的結束標記 "</head>問題

事件背景:

今天就碰到了這樣的問題,

org.xml.sax.SAXParseException: 元素型別 "head" 必須由匹配的結束標記 "</head>

我本地編譯的時候報錯,上面報錯,起初 我以為是我畫的html頁面報錯呢,一個個標籤查呀,查了一個多小時沒結果

原因:

spring-boot-starter-thymeleaf對html5預設校驗要求高。一言不合就報錯如下:

解決方案:

1、在pom.xml中新增依賴

<!--啟用不嚴格檢查html-->
<dependency>
   <groupId>net.sourceforge.nekohtml</groupId>
   <artifactId>nekohtml</artifactId>
   <version>1.9.22</version>
</dependency>

2、在 application.properties

 

2.1、關閉快取

 spring.thymeleaf.cache=false

 

2.2、修改

spring.thymeleaf.mode=LEGACYHTML5

 

參考文章:https://blog.csdn.net/zpengf/article/details/80096346