依赖
<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);