如何在Velocity模板中检索哈希映射的值

3
如何在Velocity模板中从以下哈希图中检索值?请帮忙。
LinkedHashMap<String, LinkedHashMap<Integer, Object>> hashmap = new LinkedHashMap<String, LinkedHashMap<Integer,Object>>();
2个回答

10

首先,在Java后端类中添加哈希映射(参考这里)。

context.put("myhashmap", hashmap);

然后您可以在Velocity模板中的任何位置引用,例如:

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

0
这对我有用:
$!myhashmap.get($!foo).toString();

注意:在我的情况下,foo 是一个变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接