zoukankan      html  css  js  c++  java
  • (转)spring-boot thymeleaf对没有结束符的HTML5标签解析出错解决办法

    使用springboot的thymeleaf模板时默认会对HTML进行严格的检查,导致当你的标签没有闭合时就会通不过,例如:

    //要想通过,后面的闭合必须写成  />
    <meta charset="UTF-8">

    个人发现不仅是HTML代码会这样,js代码同样会这样,例如:

    //这里的i<10同样通不过
    for(var i=0;i<10;i++){
    ...
    }

    解决办法:

    1. 引入nokohtml库
      <!--启用不严格检查html-->
       <dependency>
          <groupId>net.sourceforge.nekohtml</groupId>
          <artifactId>nekohtml</artifactId>
          <version>1.9.22</version>
       </dependency>
    2. 修改配置文件application_dev.yml加入
       thymeleaf:
         mode: LEGACYHTML5
    3. 或者在application.properties中增加
      spring.thymeleaf.mode=LEGACYHTML5

      即声明thymeleaf使用非严格的html

  • 相关阅读:
    idea自定义servlet模板
    jsp基础-指令,内置对象,动作,EL表达式,JSTL技术
    cookie和session
    HttpServletRequest
    IO字符流
    IO字节流
    递归
    File 类
    JDBC数据库连接
    Map接口
  • 原文地址:https://www.cnblogs.com/unique1319/p/7402143.html
Copyright © 2011-2022 走看看