package com.froad.openapi.common.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import com.froad.openapi.common.FreeMarkerUtil;
import com.froad.openapi.util.ExceptionMsgFormat;
import freemarker.template.Configuration;
import freemarker.template.Template;
public class FreeMarkerUtilImpl implements FreeMarkerUtil{
final Log logger = LogFactory.getLog(FreeMarkerUtilImpl.class);
private Map<String, String> templatePathMap ;//= new HashMap<String, String>();
private Map<String, Template> templateMap = new HashMap<String, Template>();
public FreeMarkerUtilImpl() {
//initTemplateMap();
}
public void initTemplateMap() {
if(null != templatePathMap && templatePathMap.size() > 0) {
for (String key : templatePathMap.keySet()) {
try {
templateMap.put(key, freeMarkerConfigurer.getConfiguration().getTemplate(templatePathMap.get(key)));
} catch (Exception e) {
logger.error(ExceptionMsgFormat.errorMessageFormat(e));
}
}
}
}
public Map<String, String> getTemplatePathMap() {
return templatePathMap;
}
public void setTemplatePathMap(Map<String, String> templatePathMap) {
this.templatePathMap = templatePathMap;
}
@Autowired
private FreeMarkerConfigurer freeMarkerConfigurer;
@Autowired
private Configuration freeMarkerConfiguration;
private List<String> templatePath = new ArrayList<String>();
public void setFreeMarkerConfigurer(
FreeMarkerConfigurer freeMarkerConfigurer) {
this.freeMarkerConfigurer = freeMarkerConfigurer;
}
public void setFreeMarkerConfiguration(Configuration freeMarkerConfiguration) {
this.freeMarkerConfiguration = freeMarkerConfiguration;
}
public String getContent(String templateName, Map<String, Object> model) {
try {
Template t = this.templateMap.get(templateName);
return FreeMarkerTemplateUtils.processTemplateIntoString(t, model);
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ExceptionMsgFormat.errorMessageFormat(ex));
try {
Template t = this.templateMap.get(templateName);
return FreeMarkerTemplateUtils.processTemplateIntoString(t,
model);
} catch (Exception e) {
e.printStackTrace();
logger.error(ExceptionMsgFormat.errorMessageFormat(ex));
}
}
return null;
}
}
配置文件
<bean id="freeMarkerUtil" class=“openapi.common.impl.FreeMarkerUtilImpl" init-method="initTemplateMap">
<property name="freeMarkerConfigurer" ref="freeMarkerConfigurer" />
<property name="freeMarkerConfiguration" ref="freeMarkerConfiguration" />
<property name="templatePathMap" ref="templatePathMap"></property>
</bean>
<bean id="templatePathMap" class="java.util.HashMap">
<constructor-arg>
<map>
<entry key="Android_SD_Fail.page">
<value>Android_SD_Fail.page</value>
</entry>
相关推荐
freemarker根据模板生成word,freemarker根据模板生成word,freemarker根据模板生成word
Freemarker模板生成pdf+javaFreemarker模板生成pdf+javaFreemarker模板生成pdf+javaFreemarker模板生成pdf+javaFreemarker模板生成pdf+java
3.写java程序根据模板生成word 总结,之前在网上查到这个资料怎么调试都失败,后来经过反复查找发现是编码问题导致生成word格式错误,已经修正,希望能给大家带来帮助。 效率测试生成100000行数据大概4000毫秒...
freemarker根据模版生成文件使用例子
Java freemarker 模板生成word动态表格
最近在做一个出卷系统,需要通过试卷模板从数据库中抽取题目,然后按照模板的样式生成完整的试卷,包括试卷格式的排版和图片的写入。这是用freemarker模板生成word文档。里面包括完整代码和所需jar包。
freemarker html生成pdf 通过freemarker 和html模板生成对应的pdf或者图片 参考使用,欢迎下载
通过程序生成PDF文件, wkhtmltox-0.12.3.2_msvc2013-win64.exe html-url
Freemarker+poi 模板生成word+导入图片 直接导入eclipse即可,希望对大家有所帮助
Java利用Freemarker模板自动生成dto、dao、rowmapper、bo、service代码,代码可以直接复制到项目中使用,代码是基于pring框架的
freemarker实现代码生成器详细教程
通过三种不同的方式(freemarker+jfreechart、xDoc、POI),根据模板创建Word文件。可以动态修改Word中表格(table)、图表(chart)等数据。导入工程后,可直接运行xxxDemo文件,查看文档生成效果。详见压缩包中的...
基于Freemarker模板的纯Java代码实现的代码生成器工具
Freemarker利用模板生成word的使用(java生成word),切记word模板制作用03版的,其他版本会报资源损坏的提示!
freemarker模板生成例子 可以根据表名生成其增删改查方法以及jsp页面,基于spirng,spring-mvc,mybatis .使用前请更改jdbc配置文件下的项目路径和数据库,生成后需要将controller上方注释复制到mybatisconfig中对应...
template文件夹下放入xml模板,运行Test.java文件,可以生成word文档
基于Freemarker模板的代码生成器实体映射xml的ftl模板文件
对于没有使用宏、函数等word、excel,需要按模板动态生成word、excel、html,只需要一个freemarker,先将word、excel、html等另存为**xml**,即可使用模板动态生成文件,目前xlsx是不支持的 4. PdfTemplate 对于不会...
本列springmvc采用freemarker动态生成word,并根据需求附带了word中添加图片的方法,将图片转换成Base64字符串,写入模板中。
利用freemarker 模板生成pdf ,利用easypoi 生成excel(带图片,水印,分页)