一、Maven添加引入`
<!-- freemarker -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
二、在application.properties文件中配置freemarker
spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.charset=utf-8
spring.freemarker.cache=false
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.expose-spring-macro-helpers=true
spring.freemarker.suffix=.ftl
三、目录结构
四、控制器使用@Conntroller注解
五、页面部分
六、配置完成 运行
附:application.yml
spring:
freemarker:
allow-request-override: false
cache: false
check-template-location: true
charset: utf-8
content-type: text/html
expose-request-attributes: true
expose-session-attributes: true
expose-spring-macro-helpers: true
suffix: .ftl
template-loader-path: classpath:/templates/