为列表中的 mapList 设置模板 FreeMarker
Setting Template FreeMarker for mapList inside a List
我有这样的数据模型,
contentList = [
{ "Product" : "Book", "Qty" : 10 },
{ "Product" : "Pencil", "Qty" : 10 }
]
我想在这样的模板中显示它
PRODUCT QUANTITY
1. Book 10
2. Pencil 10
当我使用此代码时,
<#list contentList as content>
<#assign i = 1>
<#list content?keys as key>
${key}: ${content[key]}
<#assign i = i + 1>
</#list>
</#list>
结果是这样的
1. Book
2. 10
1. Pencil
2. 10
我用这个link来测试,https://try.freemarker.apache.org/
已经自己搞定了。对于数据模型,我使用这个
contentMap = {
"Book" : 10,
"Pencil" : 10
}
在我的模板中我使用这个
<#list contentMap as key, value>
${key} : ${value}
</#list>
我有这样的数据模型,
contentList = [
{ "Product" : "Book", "Qty" : 10 },
{ "Product" : "Pencil", "Qty" : 10 }
]
我想在这样的模板中显示它
PRODUCT QUANTITY
1. Book 10
2. Pencil 10
当我使用此代码时,
<#list contentList as content>
<#assign i = 1>
<#list content?keys as key>
${key}: ${content[key]}
<#assign i = i + 1>
</#list>
</#list>
结果是这样的
1. Book
2. 10
1. Pencil
2. 10
我用这个link来测试,https://try.freemarker.apache.org/
已经自己搞定了。对于数据模型,我使用这个
contentMap = {
"Book" : 10,
"Pencil" : 10
}
在我的模板中我使用这个
<#list contentMap as key, value>
${key} : ${value}
</#list>