最近项目中使用到了,对word模板进行编辑和渲染,所以使用到了模板引擎技术。
在项目中,我们前端使用的富文本编辑器,进行展示和保存(和word格式一致),后端采用了freemarker进行数据的渲染。前端,就不多说了,处理很简单,只有一个展示,一个保存操作。
后台,需要获取模板和数据,进行渲染后返回到前台,进行展示。
目前实现了输入字符串和输入文件两种形式。(20180409)
freemark技术的整合和使用如下:
1.引入maven依赖
org.freemarker
freemarker
2.3.23
2.封装为utils工具类使用
importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileOutputStream;importjava.io.OutputStreamWriter;importjava.io.StringWriter;importjava.util.HashMap;importjava.util.Map;importorg.apache.log4j.PropertyConfigurator;importcom.winning.Application;importcom.winning.polaris.admin.service.impl.UpgradeServiceImpl;importcom.winning.polaris.comm.util.LogUtil;importfreemarker.cache.StringTemplateLoader;importfreemarker.template.Configuration;importfreemarker.template.Template;public classFreemarkerUtils