How to retrieve hashmap values in velocity template

半城伤御伤魂 提交于 2019-12-07 16:10:38

问题


How to retrieve values from the following hashmap in velocity template? Please help..

LinkedHashMap<String, LinkedHashMap<Integer, Object>> hashmap = new LinkedHashMap<String, LinkedHashMap<Integer,Object>>();

回答1:


First, add the hashmap to your backing Java class (reference here).

context.put("myhashmap", hashmap);

Then you can reference anywhere in your Velocity template, e.g:

<span>$myhashmap.get("foo").get(1).toString()</span>



回答2:


This worked for me:

$!myhashmap.get($!foo).toString();

Note: foo is a variable in my case.



来源:https://stackoverflow.com/questions/13416034/how-to-retrieve-hashmap-values-in-velocity-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!