首先在pom.xml中导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
之后要在application.properties或application.yml中加入相关的配置:
application.properties:
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false #关闭模板缓存
spring.thymeleaf.prefix=classpath:/templates/ #前缀
spring.thymeleaf.suffix=.html #后缀
添加Controller
package com.han.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author han
* @version 1.0
* @since 2022-12-21 22:42
*/
@Controller
public class TestController {