freemarker中map的创建以及map的遍历循环

freemarker中map的创建以及map的遍历循环

<#--创建一个map,注意在freemarker中,map的key只能是字符串来作为key-->
    <#assign userMap={"1","刘德华","2":"张学友"}/>
    

1.获取map中的值

    ${userMap["1"]}

2.获取map的keys

<#assign  keys=userMap?keys/>

3.遍历map 首选获取key的集合

<#list keys as key>
    key:${key}-value:${userMap["${key}"]}
</#list>

4.直接遍历map的第二种方式

<#list userMap?keys as key>
    key:${key}--value:${userMap["${key}"]}
</#list>

5.直接遍历map的values

<#list userMap?values as value>
    ${value}
</#list>
Last modification:October 24th, 2019 at 02:51 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment