一、引入依赖
<!--templates-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
二、设置配置
#thymeleaf配置
#模板的模式,支持如:HTML、XML、TEXT、JAVASCRIPT等
spring.thymeleaf.mode=HTML5
#编码,可不用配置
spring.thymeleaf.encoding=UTF-8
#内容类别,可不用配置
spring.thymeleaf.servlet.content-type=text/html
#开发配置为false,避免修改模板还要重启服务器
spring.thymeleaf.cache=false
#配置模板路径,默认就是templates,可不用配置
spring.thymeleaf.prefix=classpath:/templates/
三、配置控制类
@Controller
@RequestMapping("templates")
//@AccountBaseRight(roles = {"admin"})
public class testController {
@Operation(summary = "根据ID获取数据详情")
@RequestMapping("index")
public String test(ModelMap map){
map.addAttribute("username", "蘑菇头");
map.addAttribute("password", "123456789");
map.put("tes", "你好");
return "index";
}
四、加入template
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
</head>
<body>
<p>在webapp下面的资源可以访问到templates下面的资源,原因是webapp在加载的时候会放到classpath下面去</p>
<p>所以可以进行交互,互相访问</p>
<a href="templates/index">index</a>
<a href="templates/back">more</a>
</body>
</html>