1.导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.修改application.yml配置文件
spring:
resources:
static-locations:
- classpath:/static/ #指定静态资源的存放路径, 可以直接进行访问
freemarker:
suffix: .ftl
template-loader-path:
- classpath:/templates/ #指定ftl模板文件的存放路径
3.在templates目录下新建index.ftl
模板文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>login success</h1>
<p>${txt}</p>
</body>
</html>
4.编写controller控制器
@Controller
public class FreemarkerController {
@GetMapping("/dsa")
public String asd(Model model) {
model.addAttribute("txt", "niupi");
return "asd";
}
}