简体   繁体   中英

iterate through hashmap in freemarker

I have a hashmap like below

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();
}

My FTL:

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

Above code is just an example. My question is if I loop the testStatus hashmap to have different values in each loop and clear at the end of loop... how can I have the freemarker to display the key-value pair of testStatus hashmap from each loop.

If I don't clear the testStatus hashmap I get accumulated result. But if I clear the testStatus hashmap the freemarker displays nothing..

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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