1.添加依赖
<!-- thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
2.修改配置
spring:
# thymeleaf配置
thymeleaf:
prefix: classpath:/templates/ # 路径
suffix: .html # 后缀
mode: html # 模式
encoding: utf-8 # 编码
content-type: text/html # 格式
cache: false # 缓存
3.静态文件访问路径
spring:
# 配置静态资源路径
# 前台访问静态资源时应该按照:
# <link rel="stylesheet" type="text/css" th:href="@{/static/index/css/index.css}">
# 按照该示例引用静态资源
# 说明:spring.resources.static-locations = classpath:/static/
# 该写法已过时
# 请按照以下配置配置:
# spring.web.resources.static-locations = classpath:/static/
web:
resources:
static-locations: classpath:/static/
mvc:
static-path-pattern: static/**