
当Map里面的key 是Object(String,Integer,etc)等要通过以下的方式来得到
<#list testMapkeys as testKey>< option value="${testKey}" >
${testMapget(testKey)}
</option>
</#list>
或者使用:
<#list testMapkeySet() as testKey>< option value="${testKey}" >
${testMapget(testKey)}
</option>
</#list>
切记在webwork自带的freemarker中对Map中Key的定义为String类型(如果你想用${Map[key]}这样取值的话;如果用${Mapget(key}这样取值就可以用其他类型,如Map<Long,Object>),更高片本是否可以用其他类型本人未曾验证
<#list pagermapget("m") as list><li<#if (list_index + 1) % 4 == 0> class="end"</#if>>
<a href="${base}${listhtmlFilePath}" class="productImage" target="_blank">
<img src="${base}${(listproductImageList[0]thumbnailProductImagePath)!systemConfigdefaultThumbnailProductImagePath}" alt="${listname}" />
</a>
<div class="productTitle">
<#if (listnamelength < 28)>
<a href="${base}${listhtmlFilePath}" alt="${listname}" target="_blank">${listname}</a>
<#else>
<a href="${base}${listhtmlFilePath}" alt="${listname}" target="_blank">${listname[025]}</a>
</#if>
</div>
<div class="productBottom">
<div class="productPrice">
<span class="price">${listpricestring(priceCurrencyFormat)}</span>
<span class="marketPrice">${listmarketPricestring(priceCurrencyFormat)}</span>
</div>
<div class="productButton">
<input type="button" name="addCartItemButton" class="addCartItemButton addCartItem {id: '${listid}'}" <#if listisOutOfStock>value="缺货" disabled<#else>value="购买"</#if> hidefocus="true" />
<input type="button" name="addFavoriteButton" class="addFavoriteButton addFavorite {id: '${listid}'}" value="收藏" hidefocus="true" />
</div>
</div>
</li>
</#list>
freemarker在生成模板的时候,当前数据模型的上下文是个SimpleHash 的hash结构,{a=1,b=2,},我猜想题主是想遍历一下{}中所有的变量,但是在当前上下文这个{}在ftl中是没有名字的,所以没有办法在ftl中通过${name}的方式拿到整个数据模型上下文;
但是可以通过Debug跟踪源码的方式获得,我通常的做法是(SpringMVC+Freemarker):在FreeMarkerView的processTemplate(Template template, SimpleHash model, >
以上就是关于freemarker 遍历map总是出错,请问哪里有问题么全部的内容,包括:freemarker 遍历map总是出错,请问哪里有问题么、freemarker如何遍历模板中所有变量、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)