pom.xml文件里引入jar包是必须的:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
接下来是freemarker的一些配置在application.yml文件:
freemarker:
request-context-attribute: rc
allow-request-override: false
cache: true
enabled: true
check-template-location: true
charset: UTF-8
content-type: text/html
expose-request-attributes: true
expose-session-attributes: true
expose-spring-macro-helpers: false
template-loader-path: classpath:/templates/
suffix: .ftl
settings:
classic_compatible: true
template_exception_handler: ignore
number_format: #
prefer-file-system-access: false
其中静态资源的配置方式,网上找的集成方式一般是配置以下几种:
# templateLoaderPath: classpath:/templates/
# static-locations: classpath:/templates/
# template-loader-path: classpath:/templates/
但是都不生效,只有配置template-loader-path后才生效