ReentrantLock ReentrantLock是JDK方法,需要手动声明上锁和释放锁,因此语法相对复杂 […]
分类: Java
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; } } |
新建springboot项目pom导入依赖:
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 |
<!-- easyexcel 主要依赖 这一个基本上就够了--> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.4</version> </dependency> <!-- servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel --> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.2.6</version> </dependency> |
[…]