在使用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
即聲明thymeleaf使用非嚴格的html。啟動之后訪問頁面會報如下錯誤:
org.thymeleaf.exceptions.ConfigurationException: Cannot perform conversion to XML from
legacy HTML:
The nekoHTML library is not in classpath. nekoHTML 1.9.15 or newer is required for
processing templates in
"LEGACYHTML5" mode [http://nekohtml.sourceforge.net]. Maven spec:
"net.sourceforge.nekohtml::nekohtml::1.9.15".
IMPORTANT: DO NOT use versions of nekoHTML older than 1.9.15.
上面的異常說的是需要依賴nekoHTML 1.9.15 or newer的版本。pom.xml中添加依賴如下
<dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> <version>1.9.22</version> </dependency>
