我们的静态页面全部存放在templates目录下 src/main/resources/templates
SpringBoot默认有以下几个模板引擎: Thymeleaf FreeMarker Velocity Groovy Mustache
引入freeMarker依赖包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
控制器
@Controller
@RequestMapping("/user")
public class UserController{
@RequestMapping("info")
public String
info(Model model
){
model
.addAttribute("username","wang");
Map
<String Object
> map
= new Map<String, Object>();
map
.puut("age",22);
model
.addAttribute("map",map
);
return "user/info";
}
}
模板
${username}
${map.age}