SpringBoot2.0整合Freemarker

这个暂时没有遇到坑,直接上码实战。

【1】pom文件

添加freemarker依赖如下:

<!--整合freemarker-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

【2】yml配置

yml中对freemarker配置如下:

spring:
    freemarker:
      cache: false
      charset: UTF-8
      content-type: text/html
      suffix: .ftl
      check-template-location: true
      template-loader-path: classpath:/templates
      expose-request-attributes: true
      expose-session-attributes: true
      expose-spring-macro-helpers: true
      request-context-attribute: request
      settings:
       default_encoding: UTF-8
       output_encoding: UTF-8
       url_escaping_charset: UTF-8
       tag_syntax: auto_detect
       locale: zh_CN
       datetime_format: yyyy-MM-dd HH:mm:ss
       date_format: yyyy-MM-dd
       time_format: HH:mm:ss

配置可以根据自己需求进行修改,这里将模板放在了src/main/resource/templates下。

如果项目打war包,你也可以选择放在webapp或者WEB-INF下,在template-loader-path处指定你的模板路径即可。


其他的参考freemarker博客列表:

https://blog.csdn.net/j080624/article/category/6441794

猜你喜欢

转载自blog.csdn.net/J080624/article/details/81533431