1.从List集合取一个Map集
例如:
Java代码: List list = new ArrayList();
Map map1 = new HashMap(); map1.put("phone", "13655555555"); map1.put("email", "admin@vip.com"); list.add(map1); Map map2 = new HashMap(); map2.put("phone", "13888888888"); map2.put("email", "china@vip.com"); 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> <#if itemKey="email"> Email:${map[itemKey]} </#if> </#list> </#list>
2. 复杂的list集合里面map,map里面套有list2集合,list2里面还有map
java代码:
- List<Map<String,Object>> typeList=new ArrayList<Map<String,Object>>();
- for(MerchantSettledTypeInfo merchantSettledType:merchantSettledTypeSet){
- Map<String,Object> typeMap=new HashMap<String,Object>();
- ProductTypeInfo type=merchantSettledType.getProductType();
- typeMap.put("id", type.getId());
- typeMap.put("name", type.getName());
- //商品分类list,里面若干个分类map
- List<Map<String,String>> categoryList=new ArrayList<Map<String,String>>();
- List<ProductCategoryInfo> categoryList =merchantSettledType.getProductCategoryListId());
- for( ProductCategoryInfo cate: categoryList){
- Map<String,String> categoryMap=new HashMap<String,String>();
- 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> <tr> <#if itemKey=="name"> <td>${(middleMap[itemKey])!}</td> </#if> <#if itemKey=="categoryList"> <#list middleMap[itemKey] as cateMap> <#list cateMap?keys as cateKey> <#if itemKey=="name"> <td>${(cateMap[cateKey])!}</td> </#if> </#list> </#list> </#if> </tr> </#list> </#list>