freemarker 遍历map总是出错,请问哪里有问题么?
ftl中是这样写的:<#listtables?keysastestKey>${testKey}</#list>报错如下:2015-11-317:24:26freemark...
ftl中是这样写的:
<#list tables?keys as testKey>
${testKey}
</#list>
报错如下:
2015-11-3 17:24:26 freemarker.log.JDK14LoggerFactory$JDK14Logger error
严重: Template processing error: "Expression tables is undefined on line 563, column 8 in report.ftl."
Expression tables is undefined on line 563, column 8 in report.ftl.
The problematic instruction:
----------
==> list tables?keys as testKey [on line 563, column 1 in report.ftl]
----------
Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression tables is undefined on line 563, column 8 in report.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
at freemarker.core.BuiltIn$keysBI._getAsTemplateModel(BuiltIn.java:668)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:221) 展开
<#list tables?keys as testKey>
${testKey}
</#list>
报错如下:
2015-11-3 17:24:26 freemarker.log.JDK14LoggerFactory$JDK14Logger error
严重: Template processing error: "Expression tables is undefined on line 563, column 8 in report.ftl."
Expression tables is undefined on line 563, column 8 in report.ftl.
The problematic instruction:
----------
==> list tables?keys as testKey [on line 563, column 1 in report.ftl]
----------
Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression tables is undefined on line 563, column 8 in report.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:135)
at freemarker.core.BuiltIn$keysBI._getAsTemplateModel(BuiltIn.java:668)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
at freemarker.core.Environment.visit(Environment.java:221) 展开
1个回答
展开全部
当Map里面的key 是Object(String,Integer,etc)等要通过以下的方式来得到
<#list testMap?keys as testKey>
< option value="${testKey}" >
${testMap.get(testKey)}
</option>
</#list>
或者使用:
<#list testMap.keySet() as testKey>
< option value="${testKey}" >
${testMap.get(testKey)}
</option>
</#list>
切记在webwork自带的freemarker中对Map中Key的定义为String类型(如果你想用${Map[key]}这样取值的话;如果用${Map.get(key}这样取值就可以用其他类型,如Map<Long,Object>),更高片本是否可以用其他类型本人未曾验证
<#list pager.map.get("m") as list>
<li<#if (list_index + 1) % 4 == 0> class="end"</#if>>
<a href="${base}${list.htmlFilePath}" class="productImage" target="_blank">
<img src="${base}${(list.productImageList[0].thumbnailProductImagePath)!systemConfig.defaultThumbnailProductImagePath}" alt="${list.name}" />
</a>
<div class="productTitle">
<#if (list.name?length < 28)>
<a href="${base}${list.htmlFilePath}" alt="${list.name}" target="_blank">${list.name}</a>
<#else>
<a href="${base}${list.htmlFilePath}" alt="${list.name}" target="_blank">${list.name[0..25]}...</a>
</#if>
</div>
<div class="productBottom">
<div class="productPrice">
<span class="price">${list.price?string(priceCurrencyFormat)}</span>
<span class="marketPrice">${list.marketPrice?string(priceCurrencyFormat)}</span>
</div>
<div class="productButton">
<input type="button" name="addCartItemButton" class="addCartItemButton addCartItem {id: '${list.id}'}" <#if list.isOutOfStock>value="缺货" disabled<#else>value="购买"</#if> hidefocus="true" />
<input type="button" name="addFavoriteButton" class="addFavoriteButton addFavorite {id: '${list.id}'}" value="收藏" hidefocus="true" />
</div>
</div>
</li>
</#list>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询