[英]How to pass and access list of complex objects and its properties to freemarker
传递给freemarker模板的Java model:
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}
您的 Map 迭代错误。 可能你应该尝试如下。
<#list invoices as invoice>
<tr>
<#list invoice.properties?keys as prop>
<td>${invoice.properties['${prop}']}<td>
</#list>
</tr>
</#list>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.