springboot配置freemarker使用application.properties

一、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/

猜你喜欢

转载自blog.csdn.net/pdsuxueyuan/article/details/86545160
今日推荐