添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
配置application.yml
spring:
freemarker:
# 设定模板的加载路径,多个以逗号分隔,默认:
tempalte-loader-path:
classpath: /templates
# 是否启用模板缓存
cache: false
charset: utf-8
# 设定模板的后缀
suffix: .ftl
创建类(可以在普通类中获取到springbean)
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class SpringContextHolder implements ApplicationContextA