zoukankan      html  css  js  c++  java
  • 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>

      

  • 相关阅读:
    利用正則表達式排除特定字符串
    js面向对象编程:this究竟代表什么?
    js调用父级frame中的方法
    Cocos2d-x动画工具类
    BZOJ 2466 中山市选2009 树 高斯消元+暴力
    Android Intent Scheme URLs攻击
    XML基础(一)
    【Life】 Never Too Late, Just Do it Better!
    代理模式
    HDU--Elevator(水题)
  • 原文地址:https://www.cnblogs.com/QW-lzm/p/8275537.html
Copyright © 2011-2022 走看看