Spring Boot里面有很多的模板供我们使用,我简单介绍下FreeMarker的集成
gradle文件加入此配置
compile('org.springframework.boot:spring-boot-starter-freemarker')
application.yml加入此配置
# freemarker静态资源配置
spring:
freemarker:
tempalte-loader-path: classpath:/templates
cache: false
charset: UTF-8
check-template-location: true
content-type: text/html
expose-request-attributes: true
expose-session-attributes: true
request-context-attribute: request
suffix: .html
在Controller配置入口,Spring Boot有两种@RectController,@Controller,前者是为ResponseBody返回的,就不需要每个方法注解返回Body,我们需要返回的是视图,类名上注解@Controller,方法体注释@RequestMapper("/name")就行了,如下图

返回的user是resources/templates下的一个html文件
配置完毕
网友评论