FreeMarker
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
spring:
freemarker:
suffix: .ftl
content-type: text/html
charset: utf-8
template-loader-path: classpath:/views/
@RequestMapping("/hello1")
public String test() {
return "hello";
}
Thymeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
spring:
thymeleaf:
prefix: classpath:/html/
cache: false
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xml:lang="en" lang="en">
<head>
<title>Title</title>
</head>
<body>
<!--获取请求域的值-->
<h2 th:text="${msg}"></h2>
</body>
</html>
@RequestMapping("/hello2")
public String test1(Model model) {
model.addAttribute("msg","hellospring");
return "hello";
}