首页
学习
活动
专区
圈层
工具
发布

SpringBoot整合Thymeleaf模板引擎

1.添加依赖

代码语言:html
复制
<!-- thymeleaf -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <version>2.3.2.RELEASE</version>
</dependency>

2.修改配置

代码语言:yaml
复制
spring:
  # thymeleaf配置
  thymeleaf:
    prefix: classpath:/templates/   # 路径
    suffix: .html                   # 后缀
    mode: html                      # 模式
    encoding: utf-8                 # 编码
    content-type: text/html         # 格式
    cache: false                    # 缓存

3.静态文件访问路径

代码语言:yaml
复制
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/**
下一篇
举报
领券