在使用springboot的過程中,如果使用thymeleaf作爲模板文件,則要求HTML格式必須爲嚴格的html5格式,必須有結束標籤,否則會報錯!解決辦法如下:
1、你可以使用嚴格的標籤,也就是每個標籤都有結束標籤,這種可能比較麻煩
2、在application.properties中增加spring.thymeleaf.mode=LEGACYHTML5,即聲明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. at org.thymeleaf.templateparser.html.AbstractHtmlTemplateParser.parseTemplate(AbstractHtmlTemplateParser.java:90) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:278) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] |
上面的異常已經說的很清楚了,需要依賴nekoHTML 1.9.15 or newer的版本。maven依賴如下
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
現在就可以正常訪問了。