1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
package com.jeeplus.modules.util; import com.jeeplus.modules.dispute.cascade.entity.DisputeTypeCascade; import java.util.List; import java.util.Map; import java.util.ArrayList; import java.util.LinkedHashMap; /** * 功能描述:返回树形的封装结构数据 <br> * @Param: * @Return: * @Author: zxw * @Date: 2020/5/22 12:57 */ public class MenuTreeUtil { public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>(); public List<DisputeTypeCascade> menuCommon; public List<Object> menuList(List<DisputeTypeCascade> menu){ //controller层调用的方法 ,并将数据以list的形式返回 this.menuCommon = menu; List<Object> list = new ArrayList<Object>(); for (DisputeTypeCascade x : menu) { Map<String,Object> mapArr = new LinkedHashMap<String, Object>(); if(x.getParent().getId().equals("0")){ mapArr.put("id", x.getId()); mapArr.put("type", x.getDisputeType()); mapArr.put("parentId", x.getParent().getId()); mapArr.put("child", menuChild(x.getId())); list.add(mapArr); } } return list; } public List<Object> menuChild(String id){ //子集查找遍历 List<Object> lists = new ArrayList<Object>(); for(DisputeTypeCascade a : menuCommon){ Map<String,Object> childArray = new LinkedHashMap<String, Object>(); if(a.getParent().getId().equals(id)){ childArray.put("id", a.getId()); childArray.put("type", a.getDisputeType()); childArray.put("parentId", a.getParent().getId()); // childArray.put("child", menuChild(a.getId())); lists.add(childArray); } } return lists; } } |