当前位置:网站首页>freemark 使用ftl文件 生成word
freemark 使用ftl文件 生成word
2022-06-23 15:07:00 【softwareDragon】
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
import freemarker.template.TemplateException;
import java.io.*;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
public class AA {
//dataMap为数据模型 ftlName为bb这个目录下的ftl文件
public static byte[] createDocForFtl(Map<String, Object> dataMap,String ftlName)
throws IOException {
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
//需要导出模板的包路径
configuration.setClassForTemplateLoading(AA.class, "/bb");
Template t = null;
try {
t = configuration.getTemplate(ftlName);
} catch (IOException e) {
e.printStackTrace();
}
Writer out = new StringWriter();
//将模板和数据模型合并生成文件
try {
//生成文件
t.process(dataMap, out);
return out.toString().getBytes();
} catch (TemplateException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
return null;
}
}边栏推荐
猜你喜欢
随机推荐
他山之石 | 微信搜一搜中的智能问答技术
Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
MySQL日志管理怎么配置
TCP协议三次握手和四次挥手抓包分析
Important knowledge of golang: waitgroup parsing
[普通物理] 半波损失 等厚与等倾干涉
[opencv450] salt and pepper noise demo
Variable declaration of go language
Starting from 3, add paging function in the business system
Android kotlin collaboration Async
积分商城要如何做才能获取到利润
golang 重要知识:mutex
Gartner's latest report: development of low code application development platform in China
Introduction to the push function in JS
golang 重要知识:sync.Cond 机制
地平线开发板 调试
Pop() element in JS
F5 application strategy status report in 2022: edge deployment and load security become the focus of attention in the Asia Pacific Region
Solution to the problem that MySQL cannot be started in xampp
xcbdfbs xcvb





