一:在application.yml中加入freemarker的配置
spring:
freemarker:
suffix: .html
二:加入freemarker的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
三:建立html文件 目录如下
四:在Controller中返回页面
完成
注意:
Controller层如果加注解@RestController必须要加上视图解析器,因为@RestController是有@Controller和@ResponseBody组成,而@ResponseBody会返回json字符串。
@RequestMapping("/index")
public ModelAndView index() {
ModelAndView mv = new ModelAndView("hello");
return mv;
}