繁体   English   中英

在freemarker中迭代hashmap

[英]iterate through hashmap in freemarker

我有一个类似下面的hashmap

HashMap<String, String> testStatus = new HashMap<String, String>();
Map root = new HashMap();

public void fmTest() {

testStatus.put("one","1");
testStatus.put("two","2");
testStatus.put("three","3");
root.put("status", testStatus);
testStatus.clear();
}

我的FTL:

<#list status?keys as key> 
${key} = ${status[key]}
</#list> 

上面的代码只是一个例子。 我的问题是,如果我循环testStatus hashmap以在每个循环中具有不同的值并在循环结束时清除...我怎样才能让freemarker从每个循环中显示testStatus hashmap的键值对。

如果我不清除testStatus hashmap,我会得到累积的结果。 但是,如果我清除testStatus hashmap,freemarker什么都不显示..

HashMap<String, String> testStatus = new HashMap<String, String>();

将此声明放入fmTest方法,然后每次调用该方法时,都会将新的Map放入根目录,因此不会累积...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM