当前位置:网站首页>freemarker的使用
freemarker的使用
2022-07-02 10:56:00 【爱窦】
依赖
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
模板内容
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:gw=\"urn:gwService\">
<SOAP-ENV:Body SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
<gw:ldtpExchStatusQuery>
<transId>${transId}</transId>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
具体使用
//设置数据
Map dataMap = new HashMap<>();
dataMap.put("transId","abc");
//设置版本号
Version version = new Version("2.3.28");
Configuration configuration = new Configuration(version);
configuration.setDefaultEncoding("utf-8");
//模板文件路径
configuration.setDirectoryForTemplateLoading(new File("D:\freemarker.xml"));
Template template = configuration.getTemplate("freemarker.xml");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(out, "utf-8");
//将数据写入模板
template.process(dataMap, w);
w.close();
byte[] bytes = out.toByteArray();
out.close();
MultipartFile file = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), bytes);//得到最终模板
边栏推荐
- [to be continued] [UE4 notes] l5ue4 model import
- Pycharm连接远程服务器
- 数据湖(十一):Iceberg表数据组织与查询
- (POJ - 1308)Is It A Tree? (tree)
- How to explain binary search to my sister? This is really difficult, fan!
- MySQL -- convert rownum in Oracle to MySQL
- 一般来讲,如果频繁出现inconsistent tab and space的报错
- 每日学习2
- Launcher启动过程
- Dingtalk 发送消息
猜你喜欢
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
Drawing Nyquist diagram with MATLAB
Launcher startup process
Integral link, inertia link and proportion link in Simulink
【文档树、设置】字体变小
混沌工程平台 ChaosBlade-Box 新版重磅发布
[Hongke technology sharing] how to test DNS server: DNS performance and response time test
(POJ - 1984) navigation nightare (weighted and search set)
ensp简单入门
Codeforces Round #803 (Div. 2)(A~D)
随机推荐
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
Selenium, element operation and browser operation methods
Quarkus learning IV - project development to deployment
Launcher startup process
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
Selenium installing selenium in pycharm
[document tree, setting] font becomes smaller
SystemServer进程
QT new project_ MyNotepad++
P3008 [usaco11jan]roads and planes g (SPFA + SLF optimization)
Subcontracting configuration of uniapp applet subpackages
给Android程序员的一些面试建议「建议收藏」
Data Lake (11): Iceberg table data organization and query
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
[USACO05JAN]Watchcow S(欧拉回路)
Some interview suggestions for Android programmers "suggestions collection"
瀏覽器驅動的下載
OpenHarmony笔记-----------(四)
Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
BeanUtils--浅拷贝--实例/原理