Freemarker iterating over hashmap keys

后端 未结 7 1321
梦毁少年i
梦毁少年i 2020-11-27 15:39

Freemarker has two collection datatypes, lists and hashmaps Is there a way to iterate over hashmap keys just as we do with lists?

So if I have a var with data lets s

7条回答
  •  醉酒成梦
    2020-11-27 16:11

    You can use a single quote to access the key that you set in your Java program.

    If you set a Map in Java like this

    Map hash = new HashMap();
    hash.put("firstname", "a");
    hash.put("lastname", "b");
    
    Map map = new HashMap();
    map.put("hash", hash);
    

    Then you can access the members of 'hash' in Freemarker like this -

    ${hash['firstname']}
    ${hash['lastname']}
    

    Output :

    a
    b
    

提交回复
热议问题