一.创建ftl的模板
准备好一份最终版本的word文档(填充好图片和文字),保存为xml格式的文档,打开该xml文档,找到图片和文字部分,用freemarker占位符代替原数据部分,最后将xml文档保存为ftl格式的模板文件。
xml格式文件更改如下:
二.freemarker模板引擎配置类
import freemarker.template.Configuration;
import freemarker.template.Template;
import sun.misc.BASE64Encoder;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
public class FreeMarkerUtil {
private static Configuration configuration = null;
private static HashMap<String, Template> allTemplates = null;
static {
configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
configuration.setClassForTemplateLoading(FreeMarkerUtil.class,"/templates/");//模板ftl文件在templates下面
/*
* allTemplates