.getTemplateByFile("");//模板路径
tmp.binding("deductXmlList", collection); // 绑定模板显示数据
result = tmp.render();
public static Template getTemplateByFile(String file) {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader();
Configuration cfg;
try {
cfg = Configuration.defaultConfiguration();
} catch (IOException e) {
logger.error(e.getMessage());
return null;
}
GroupTemplate classPathGt = new GroupTemplate(resourceLoader, cfg);
return classPathGt.getTemplate(file);
}
--模版
<?xml version="1.0" encoding="UTF-8"?>
<data>
<header>
<th>
<hd></hd>
<hd></hd>
<hd></hd>
<hd></hd>
<hd></hd>
<hd></hd>
<hd></hd>
</th>
</header>
<body>
<% for(deductXml in deductXmlList){ %>
<rd>
<td>${deductXml.payableTm,dateFormat="yyyy-MM-dd"}</td>
<td>${deductXml.waybillNo}</td>
<td>
${deductXml.strFeeDetails}
</td>
<td>
${deductXml.strDeductDetails}
</td>
<td>${deductXml.strPayableAmt}</td>
<td>${deductXml.senderCustomerName}</td>
<td>${deductXml.receiverCustomerName}</td>
</rd>
<%}%>
</body>
</data>