SpringBoot整合thymeleaf
thymeleaf 模板引擎
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.7.0</version>
</dependency>
Springboot 配置文件
# 模板引擎位置 编码 和不使用缓存
spring.thymeleaf.prefix= classpath:/templates/
spring.thymeleaf.suffix= .html
spring.thymeleaf.encoding= utf-8
spring.thymeleaf.cache= false
spring.thymeleaf.mode= HTML5
控制器测试 请求/test 跳转到 login页面 存放msg数据
@Controller
public class GameController {
@RequestMapping("/test")
public String test(){
System.out.println("Spring!!!");
model.addAttribute("msg","模板引擎123");
return "login";
}
}
模板引擎的位置

<!DOCTYPE html>
<<html lang="en" xmlns:th="http://www.thymeleaf.org" >
<head>
<meta charset="UTF-8">
<title>模板引擎</title>
</head>
<body>
<h1 th:text="${msg}"></h1>
</body>
</html>
浏览器测试


浙公网安备 33010602011771号