在速度中你可以迭代java hashmap的条目集()? [英] in velocity can you iterate through a java hashmap's entry set()?

查看:108
本文介绍了在速度中你可以迭代java hashmap的条目集()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能在速度模板中做这样的事吗?

Can you do something like this in a velocity template?

#set ($map = $myobject.getMap() )
#foreach ($mapEntry in $map.entrySet())
    <name>$mapEntry.key()</name>
    <value>$mapEntry.value()</value>
#end

它输出空白标签,如下所示:

it outputs blank tags like so:

<name></name> 

<value></value> 

我做错了什么?

推荐答案

您的错误是指 key value 作为方法(带尾随()括号)而不是属性。试试这个:

Your mistake is referring to key and value as methods (with trailing "()" parenthesis) instead of as properties. Try this:

#set ($map = $myobject.getMap() )
#foreach ($mapEntry in $map.entrySet())
    <name>$mapEntry.key</name>
    <value>$mapEntry.value</value>
#end

换句话说,使用属性,例如 mapEntry。键或方法,如 mapEntry.getKey()

In other words, use either a property, like mapEntry.key, or the method, like mapEntry.getKey().

这篇关于在速度中你可以迭代java hashmap的条目集()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆