我有一个 html 文件的打印导出,它从 map 导入,如下所示
Template t = TemplateLoader.load("Printing/acount.html");
Map<String, Object> map = new HashMap<String, Object>();
map.put("accountName ", e.accountName);
map.put("accountAmount ", acAmount);
return t.render(map);
并将参数加载到html文件
<div>
Account: <font size="3"><b>${ accountName }</b> ${accountAmount}</font> <br/>
它的导出看起来像
账户15884 5.000
如果我想导出多条记录怎么办?
可以说
账户15885 2.000
账户15886 4.000
账户15887 3.000
第二种情况下的html和java代码应该如何才能传递未知数量的记录?
最佳答案
如果你有列表,你可以这样做
map.put("accounts", theAccountList);
在模板(我假设是 FreeMarker)中,您执行以下操作:
<#list accounts as account>
<div>Account: <font size="3"><b>${account.getName()}</b> ${account.getAmount()}</font> <br/></div>
</#list>
关于java - 将 java 列表传递给 html 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998758/