- 在pom.xml文件引入thymeleaf依賴,
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
- application.properties文件添加
spring.thymeleaf.suffix=.html spring.thymeleaf.servlet.content-type=text/html; charset=utf-8 spring.http.encoding.charset=UTF-8 spring.thymeleaf.cache=false
- html使用正確的語法
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Login</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- <link th:href="@{/bootstrap/css/bootstrap.css}" rel="stylesheet" /> -->
<link th:href="@{/css/style.css}" rel='stylesheet' type='text/css' />
<script th:href="@{/js/jquery.min.js}" type="text/javascript"></script>
</head>
<style></style>
<body></body>
</html>
注意: 引入css和js的正確語法
<link th:href="@{/css/style.css}" rel='stylesheet' type='text/css' />
<script th:href="@{/js/jquery.min.js}" type="text/javascript"></script>