Java实用小工具
工具一:对Java中的List<Map<String,Object>>格式数据实现递归
/** * 递归List<Map<String,Object>> * @param treeList :递归数据 * @param parentId :父Id * @return */ public JSONArray treeRecursionDataList(List<Map<String,Object>> treeList, String parentId) { JSONArray childMenu = new JSONArray(); for (Object object : treeList) { JSONObject jsonMenu =JSONObject.parseObject(JSON.toJSONString(object)); String menuId = jsonMenu.getString("SON_ID"); //这里key值为你的子ID String pid = jsonMenu.getString("PARENT_ID"); //这里的key值为你的父ID if (parentId.equals(pid) ) { JSONArray c_node = treeRecursionDataList(treeList, menuId); jsonMenu.put("childList", c_node); childMenu.add(jsonMenu); } } return childMenu; }