application.yml配置
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML
encoding: UTF-8
servlet:
content-type: text/html
cache: false
mvc:
static-path-pattern: /static/**
pom.xml中的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
头文件
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
导入css文件
<link href="../static/css/home_1.css" th:href="@{/css/home_1.css}" rel="stylesheet"/>
导入js文件
<script th:src="@{/js/main.js}"></script>
用img添加图片
<img th:src="@{/img/banner_1.jpg}" alt="" class=" ">
用url添加背景图片
<div class=" " th:style="'background-image: url('+'/img/slides/slide_home_2.jpg'+');'">