欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

返回前端的父子结构

程序员文章站 2022-07-15 13:39:41
...
 /*
     * @Description: 查询登记类别返回父子结构
     * @Author: zhuning
     * @Date: 2020/5/28
     */
    public List<Map<String, Object>> selectDictRegisterChildrenList() throws MidException {
        List<Map<String, Object>> list = selectList(getSelectListAllSql());
        List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
        for (Map<String, Object> dataMap : list) {
            Map<String, Object> mapArr = new HashMap<String, Object>();
            if (dataMap.get("parentid").equals("")) {
                mapArr.put("id", dataMap.get("id"));
                mapArr.put("type", dataMap.get("type"));
                mapArr.put("category", dataMap.get("category"));
                mapArr.put("name", dataMap.get("name"));
                mapArr.put("parentid", dataMap.get("parentid"));
                if (menuChild((String) dataMap.get("id"), list).size() > 0) {
                    mapArr.put("children", menuChild((String) dataMap.get("id"), list));
                }
                returnList.add(mapArr);
            }
        }
        return returnList;
    }

    private List<Map<String, Object>> menuChild(String id, List<Map<String, Object>> listmap) {
        List<Map<String, Object>> lists = new ArrayList<Map<String, Object>>();
        for (Map<String, Object> dataMap2 : listmap) {
            Map<String, Object> childArray = new HashMap<String, Object>(16);
            if (id.equals(dataMap2.get("parentid"))) {
                childArray.put("id", dataMap2.get("id"));
                childArray.put("type", dataMap2.get("type"));
                childArray.put("category", dataMap2.get("category"));
                childArray.put("name", dataMap2.get("name"));
                childArray.put("parentid", dataMap2.get("parentid"));
                if (menuChild((String) dataMap2.get("id"), listmap).size() > 0) {
                    childArray.put("children", menuChild((String) dataMap2.get("id"), listmap));
                }
                lists.add(childArray);
            }
        }
        return lists;
    }
   
相关标签: Aning的成长之路