1. 新建项目:
2. src/main/resources 目录下新建templates以及static文件夹,templates里面放页面文件(.ftlh后缀文件,2.0之前后缀是.ftl),static里面放js等各种静态资源
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8"/>
<title></title>
</head>
<body>
FreeMarker模板引擎
<h1>${message}</h1>
</body>
</html>
3. 控制层
@Controller
public class PageController {
// @ResponseBody 如果需要返回json字符串就使用这个,否则默认返回页面
@RequestMapping(value = "/index")
public String showPage(Model model) {
model.addAttribute("message", "HelloWorld");
return "index";
}
}
4. poi添加依赖(不需要版本号,版本号会自动根据springboot的版本而定)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
5.application.properties
#默认8080端口
server.port=8090
# 关闭缓存,开发过程中调试可及时刷新
spring.freemarker.cache=false
6. 启动访问