springboot①集成thymeleaf支持不规范的HTML

        最近在写springboot的项目,遇到了一些问题,与大家分享一下。因为thymeleaf是springboot推荐的模板引擎,所以选择了thymeleaf。集成很简单,直接添加maven依赖:

 

pom文件加入下面内容即可:

<dependency> 

    <groupId>org.springframework.boot</groupId>  

    <artifactId>spring-boot-starter-thymeleaf</artifactId>  

</dependency>

         坑来了,springboot2.0之前的版本默认maven配置的是thymeleaf 2.*,thymeleaf 3.0以前的版本支持的模板模式(XML,HTML5,XHTML ,Legacy HTML5 等)除了Legacy HTML5之外,其他模式都必须是闭合的(标签),配置为Legacy HTML5模式可以支持不规范标签,但是还需要额外引入一个包用来处理代码

<dependency>  

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

    <artifactId>nekohtml</artifactId>  

    <version>1.9.22</version><!-- 版本自己调整,也可不动 -->

</dependency> 

    其实处理这个问题很简单,就是把thymeleaf2指定版本到3.0以上就行了,如图springboot版本是1.5.12.RELEASE,设置thymeleaf版本如图:

    代码:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
  <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
                <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>

</properties>

 

 

  <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
                <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>

</properties>

        到这里,thymeleaf集成完成。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值