freemarker 从List集合取一个Map集

从List集合取一个Map集

例如:

    List list = new ArrayList();

    Map map1 = new HashMap();
    map1.put("phone", "13655555555");
    map1.put("email", "[email protected]");
    list.add(map1);
    
    Map map2 = new HashMap();
    
    map2.put("phone", "13888888888");
    map2.put("email", "[email protected]");
    map2.put("address", "beijing");
    list.add(map2);

test.ftl文件:

<#list list as map>
    <#list map?keys as itemKey>
         <#if itemKey="phone">
            Phone:${map[itemKey]}
         
         <#if itemKey="email">
            Email:${map[itemKey]}
         
    

复杂的list集合里面map,map里面套有list2集合,list2里面还有map

    List> typeList=new ArrayList>();
    for(MerchantSettledTypeInfo merchantSettledType:merchantSettledTypeSet){

        Map typeMap=new HashMap();
        ProductTypeInfo type=merchantSettledType.getProductType();
        typeMap.put("id", type.getId());
        typeMap.put("name", type.getName());
        //商品分类list,里面若干个分类map
        List> categoryList=new ArrayList>();
        List categoryList =merchantSettledType.getProductCategoryListId());
        for( ProductCategoryInfo cate: categoryList){
            Map categoryMap=new HashMap();
            categoryMap.put("id", cate.getId().toString());
            categoryMap.put("name", cate.getName());
            categoryList.add(categoryMap);
        }
        typeMap.put("categoryList", categoryList);
        typeList.add(typeMap);

前台ftl 页面代码:

<#list productTypeCateList as middleMap>
    <#list middleMap?keys as itemKey>
        
            <#if itemKey=="name">
                ${(middleMap[itemKey])!}
            
            <#if itemKey=="categoryList">
                <#list middleMap[itemKey] as cateMap>
                    <#list cateMap?keys as cateKey>
                        <#if itemKey=="name">
                            ${(cateMap[cateKey])!}
                        
                    
                
            
        
    

demo3

原文链接

image
<#list keyan as middleMap>
    <#list middleMap?keys as itemKey>
        <#assign keys=middleMap?keys/>
        <#list keys as key>
            key:${key}
            <#if itemKey=="${key}">
                <#list middleMap[itemKey] as cateMap>
                    数字:${cateMap.rid!}
                
            
        
    

你可能感兴趣的:(freemarker 从List集合取一个Map集)