1.导入相关依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.注入这个依赖的configration类
@Autowired
private Configuration configuration;
3.通过configration的gettemplate方法把事先准备的ftl模板传进去生成一个模板对象
Template template = configuration.getTemplate("article.ftl");
4.创建一个缓存流out
StringWriter out = new StringWriter();
5.把事先准备好的内容封装成一个map
Map<String, Object> map = new HashMap<>();
map.put("content", JSONArray.parseArray(content));
6.调用configration的process方法传入map和out生成模板
template.process(map, out);