springboot使用thymeleaf 解析异常



  在使用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>

 

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM