一、 配置maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
二、Freemarker配置
#freemarker
spring.freemarker.allow-request-override=false
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.html
spring.freemarker.content-type=text/html
spring.freemarker.enabled=true
spring.freemarker.cache=false
spring.freemarker.check-template-location=true
spring.freemarker.template-loader-path=classpath:/templates/html/
spring.freemarker.charset=utf-8
三、 控制器类
@Controller
public class UserController {
@RequestMapping("/login")
public String login(HttpServletRequest request){
request.setAttribute("name", "test freemarker");
return "login";
}
}
四、 html文件
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登陆</title>
</head>
<body>
${name}
</body>
</html>
五、结果