spring boot解决thymeleaf标签未关闭错误

来源:互联网 发布:linux dd备份 编辑:程序博客网 时间:2024/06/06 02:07

在首次使用thymeleaf时 常出现此错误 如:

<meta content="text/html;charset=utf-8"/>

<input type="text" name="username"/>

标签尾部未加“/”都会报错。


解决方案:

添加依赖:

  gradle:
         compile('net.sourceforge.nekohtml:nekohtml')
  
  maven:
          <dependency>   
              <groupId>net.sourceforge.nekohtml</groupId>  
              <artifactId>nekohtml</artifactId>   
          </dependency>


然后修改spring boot配置文件,设置thymeleaf.mode: LEGACYHTML5

thymeleaf:    cache: false    mode: LEGACYHTML5

如果是用xml配置

<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">    <property name="templateMode" value="LEGACYHTML5"/>    <property name="cacheable" value="false"/></bean>

原创粉丝点击