第一步:添加依赖,springboot中集成了thymeleaf,所以用springboot中的依赖就行
<!--模板引擎-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
第二步:修改配置文件
thymeleaf:  #thymeleaf配置
    cache: false
    prefix: classpath:/WEB-INF/view/
    suffix: .html
    encoding: UTF-8
    content-type: text/html
    mode: html5
mvc:
    static-path-pattern: /WEB-INF/view/**  # 静态资源路径
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
问题总结:
使用过程中报错 :
org.xml.sax.SAXParseException: 元素类型 "link" 必须由匹配的结束标记 "</link>" 终止
错误原因:thymeleaf对html语言较严格,如果不是HTML5的话,基本会报这个错
解决办法:
1.添加依赖
<!--启用不严格检查html-->
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
        </dependency>
2.修改配置文件,将mode参数改成这样既可
thymeleaf:
    mode: LEGACYHTML5
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.