一、添加依赖
<!--thymeleaf依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--热部署spring-boot-devtools-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
二、application.yml 配置文件
spring:
#模版配置
thymeleaf:
#避免修改模版后还要重启
cache: false
#模版路径,默认为templates(可忽略)
prefix: classpath:/templates/
#检查模版位置(可忽略)
check-template-location: true
#模版后缀,默认html(可忽略)
suffix: .html
encoding: UTF-8
servlet:
content-type: text/html
#模版模式
mode: HTML
三、新建controller
@GetMapping(value = "/login")
public String login() {
return "login";
}
四、在templates中建login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>hello world</p>
</body>
</html>
五、File->settings->Build,Execution,Deployment->Complier:勾选Build project automatically -> apply ->ok
![](https://i-blog.csdnimg.cn/blog_migrate/cbeb20083f9db05bd09eaf68b9a9cb32.png)
六、shift + alt + ctrl + /
![](https://i-blog.csdnimg.cn/blog_migrate/64a7517659435c469ce94088105fd579.png)
![](https://i-blog.csdnimg.cn/blog_migrate/bcf1b08e99ef6307e9882a2a39f885ab.png)
至此当你修改 HTML 时已经不需要重启项目了,解决了调试页面布局以及小的改动就要充气项目的烦恼!