传递给freemarker模板的Java模型:
public clazz {
public void methodOne() {
List<InvoiceObject> invoices = new ArrayList<>();
Map<String, String> properties = ImmutableMap.<String, String>builder()
.put("invoiceNumber", invoiceNumber)
.build();
invoices.add(InvoiceObject.builder().properties(properties).build());
// adding model as atribbute and invoiking process method
}
@Data
@Builder
public static class InvoiceObject { // inner class
public Map<String, String> properties;
}
}
模板:
<#list invoices as invoice>
<tr>
<td>${invoice.properties["invoiceNumberBuy"]}<td>
</#list>
结果为:
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing
更新:
模板必须具有invoiceNumber
而不是invoiceNumberBuy
。
$ {invoice.properties.invoiceNumber}
答案 0 :(得分:0)
您的地图迭代错误。可能您应该尝试以下操作。
<#list invoices as invoice>
<tr>
<#list invoice.properties?keys as prop>
<td>${invoice.properties['${prop}']}<td>
</#list>
</tr>
</#list>