简体   繁体   中英

How to get value from HashMap in Freemarker template?

How to get value from HashMap in Freemarker template if Map<String, MyObject> ?

I have Data Structure ex.: Map<String, List<MyObject>> , how to get all values from this Map in Freemarker Template?

Please check the documentation on how to iterate over collections/sequences.

<#list products as k, v>
    <p>${v}: ${v}
</#list>

If you want to iterate over the values only then use:

<#list myHash?values as v>
    ${v}
</#list>

The documentation link can be found here .

Also check the answers from these questions, they might help you: link1 and link2 .

Update:

The previous examples the variable v is a list since your map is Map<String, List<Object>> . If you want to access each item in the list you need a double iteration.

<#list myMap as k, v>
    <#list v as x>
        <p> ${x}
    </#list>
</#list>

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