溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

springboot使用thymeleaf時報html沒有結(jié)束標(biāo)簽

發(fā)布時間:2020-07-24 18:59:01 來源:網(wǎng)絡(luò) 閱讀:3662 作者:拎壺沖521 欄目:開發(fā)技術(shù)

在使用springboot的過程中,如果使用thymeleaf作為模板文件,則要求HTML格式必須為嚴(yán)格的html5格式,必須有結(jié)束標(biāo)簽,否則會報錯!解決辦法如下:

1、你可以使用嚴(yán)格的標(biāo)簽,也就是每個標(biāo)簽都有結(jié)束標(biāo)簽,這種可能比較麻煩

2、在application.properties中增加spring.thymeleaf.mode=LEGACYHTML5,即聲明thymeleaf使用非嚴(yán)   格的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]

 上面的異常已經(jīng)說的很清楚了,需要依賴nekoHTML 1.9.15 or newer的版本。maven依賴如下

    <dependency>

    <groupId>net.sourceforge.nekohtml</groupId>

<artifactId>nekohtml</artifactId>

<version>1.9.22</version>

</dependency>

 現(xiàn)在就可以正常訪問了。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI