解析springboot使用thymeleaf時報html沒有結束標籤

轉自:點擊打開鏈接


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

1、你可以使用嚴格的標籤,也就是每個標籤都有結束標籤,這種可能比較麻煩

2、在application.properties中增加spring.thymeleaf.mode=LEGACYHTML5,即聲明thymeleaf使用非嚴 格的html。啓動之後訪問頁面會報如下錯誤:

1
2
3
4
5
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 [<a rel="nofollow" href="http://nekohtml.sourceforge.net" target="_blank">http://nekohtml.sourceforge.net</a>]. 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>

現在就可以正常訪問了。

以上就是解析springboot使用thymeleaf時報html沒有結束標籤的詳細內容,更多請關注php中文網其它相關文章!


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