springboot之thymeleaf

如果想在springboot中使用thymeleaf的话,需要两步:

  1. 在pom.xml文件中添加如下依赖:

# pom.xml
<!-- 用于解析html文件 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

  2. 在application.properties配置文件中添加如下配置:

#  application.properties

#配置解析html
spring.thymeleaf.prefix=/WEB-INF/content/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时设置为false,否则看不到实时的页面
spring.thymeleaf.cache=false

  其中 prefix 是你的html文件的所在位置前缀,跟你的文件存放位置而改变。

  需要注意的是  thymeleaf  解析的html中的内容,标签必须是成对出现的,不然会报错导致无法运行,例如:<meta charset="UTF-8"></meta>

原文地址:https://www.cnblogs.com/wangyusu/p/11758357.html