包含了父子关系的单位对象的List数据转成树状结构

这篇具有很好参考价值的文章主要介绍了包含了父子关系的单位对象的List数据转成树状结构。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

你知道的越多,你不知道的越多
点赞再看,养成习惯
如果您有疑问或者见解,或者没有积分想获取项目和定制项目,欢迎指教:
企鹅:869192208

需求

将一个包含了父子关系的单位对象的 List 数据,转成一个带层级关系的数据。文章来源地址https://www.toymoban.com/news/detail-529883.html

原始数据,用 json 格式展示
[
    {
        "areaName": "广东省",
        "areaSeq": "BQ6Ig2ewmu51ja1XlUQ",
        "credNum": "13440000455857174Y",
        "delFlag": "0",
        "type": "1",
        "unitCode": "GEqONvGif1pkgeypVsW",
        "unitName": "广东省残疾人联合会"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "27DYBhqxPhWkxyyShIZ",
        "type": "2",
        "unitCode": "5coZCC2viVbTAotmTIW",
        "unitName": "测试部门"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "114400006715714882",
        "delFlag": "0",
        "type": "1",
        "unitCode": "27DYBhqxPhWkxyyShIZ",
        "unitName": "测试"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "1yfUGoRc0EVyejByf9a",
        "type": "2",
        "unitCode": "iaqpYx0lUKzrum8oYMl",
        "unitName": "事项测试部门43"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000006941354C",
        "delFlag": "0",
        "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
        "type": "1",
        "unitCode": "1yfUGoRc0EVyejByf9a",
        "unitName": "市场处"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000553612461J",
        "delFlag": "0",
        "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
        "type": "1",
        "unitCode": "6DZWgfIUzHa0wk8ixKz",
        "unitName": "广东省人力资源和社会保障厅"
    },
    {
        "areaName": "中国",
        "areaSeq": "VkThH0HKYsm6uLB1vSU",
        "delFlag": "0",
        "parentUnitCode": "N0mcwIHkncfZJG3jj0E",
        "type": "2",
        "unitCode": "k2OHsF7ZnpYADkJbiGi",
        "unitName": "教育厅-1部门"
    },
    {
        "areaName": "中国",
        "areaSeq": "VkThH0HKYsm6uLB1vSU",
        "delFlag": "0",
        "parentUnitCode": "N0mcwIHkncfZJG3jj0E",
        "type": "1",
        "unitCode": "TLgo7tY9HbD9TMZqRxL",
        "unitName": "教育厅-1单位"
    },
    {
        "areaName": "中国",
        "areaSeq": "VkThH0HKYsm6uLB1vSU",
        "credNum": "11440000006940116U",
        "delFlag": "0",
        "type": "1",
        "unitCode": "N0mcwIHkncfZJG3jj0E",
        "unitName": "广东省教育厅"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "pylto8i5gezxWPsLulf",
        "type": "2",
        "unitCode": "dAVzZSmgFAuBhk05Tmw",
        "unitName": "审批科"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440100MB2C91891K",
        "delFlag": "0",
        "type": "1",
        "unitCode": "pylto8i5gezxWPsLulf",
        "unitName": "广州市市场监督管理局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "6DZWgfIUzHa0wk8ixKz",
        "type": "2",
        "unitCode": "FMZpUJ3fCtnllZAAXPT",
        "unitName": "测试部门-2-1"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
        "type": "2",
        "unitCode": "hMAxUNUDfBdlRT6P5NT",
        "unitName": "文物局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "xWKRcZWjYTtuy5gMqmq",
        "type": "2",
        "unitCode": "P0ZjaRLjCaTmk1vCs0t",
        "unitName": "事项测试子部门"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "114400000069411352",
        "delFlag": "0",
        "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
        "type": "1",
        "unitCode": "xWKRcZWjYTtuy5gMqmq",
        "unitName": "审核处"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
        "type": "2",
        "unitCode": "PCkQHkCqBQ8G433PlpN",
        "unitName": "准入处"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000MB2C87614P",
        "delFlag": "0",
        "type": "1",
        "unitCode": "8wUPbECBVx75UqQ6gjM",
        "unitName": "文旅局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "rBzaXFIRKovid7dgbyY",
        "type": "2",
        "unitCode": "KZlSpr0M9svbTxswtVp",
        "unitName": "001部门"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000K30220376L",
        "delFlag": "0",
        "type": "1",
        "unitCode": "rBzaXFIRKovid7dgbyY",
        "unitName": "密码局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "t9nq70CPS9PCwrL7ury",
        "type": "2",
        "unitCode": "IA6mo3clsYao9qRqVKB",
        "unitName": "测试单位4-部门2"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "z5N2zSetiup81QAJzok",
        "type": "2",
        "unitCode": "PqIu1vdrPEMcgw9QLil",
        "unitName": "测试单位-部门2"
    },
    {
        "areaName": "中国",
        "areaSeq": "VkThH0HKYsm6uLB1vSU",
        "delFlag": "0",
        "parentUnitCode": "yK78GEa2MyLoTsv7cl8",
        "type": "2",
        "unitCode": "oL5ku79eKjSD3wsonE2",
        "unitName": "测试单位3-部门2"
    },
    {
        "areaName": "中国",
        "areaSeq": "VkThH0HKYsm6uLB1vSU",
        "delFlag": "0",
        "parentUnitCode": "yK78GEa2MyLoTsv7cl8",
        "type": "2",
        "unitCode": "NZ7nrjiR2Ipp4jUvwdg",
        "unitName": "测试单位3-部门1"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "z5N2zSetiup81QAJzok",
        "type": "2",
        "unitCode": "IyfejZ9DXBX24OararK",
        "unitName": "测试单位-部门1"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "rdF29TiDg8A6uAhtwy8",
        "type": "2",
        "unitCode": "iAeyIFab9QYfW1qnqIB",
        "unitName": "测试单位2-部门2"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "rdF29TiDg8A6uAhtwy8",
        "type": "2",
        "unitCode": "4AE4Eec19qlquekC67b",
        "unitName": "测试单位2-部门1"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "t9nq70CPS9PCwrL7ury",
        "type": "2",
        "unitCode": "wBaWrcxKXAORTsr7PXr",
        "unitName": "测试单位4-部门1"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "EG3iCBPm7bldC2esW1f",
        "type": "2",
        "unitCode": "RmCztFLB1Ip4Tl0Lcyk",
        "unitName": "hello单位-1001部门"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000006940140C",
        "delFlag": "0",
        "type": "1",
        "unitCode": "EG3iCBPm7bldC2esW1f",
        "unitName": "市民政局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "wl4XDGhZg71ntFXT8aL",
        "type": "2",
        "unitCode": "l29g1aszyjTCLmGgKMU",
        "unitName": "one测试部门"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000006939908P",
        "delFlag": "0",
        "type": "1",
        "unitCode": "wl4XDGhZg71ntFXT8aL",
        "unitName": "市医保局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000006939799Q",
        "delFlag": "0",
        "type": "1",
        "unitCode": "t9nq70CPS9PCwrL7ury",
        "unitName": "市人社局"
    },
    {
        "areaName": "中国",
        "areaSeq": "VkThH0HKYsm6uLB1vSU",
        "credNum": "11440000MB2D023437",
        "delFlag": "0",
        "type": "1",
        "unitCode": "yK78GEa2MyLoTsv7cl8",
        "unitName": "食药监局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "11440000MB2D02159F",
        "delFlag": "0",
        "type": "1",
        "unitCode": "rdF29TiDg8A6uAhtwy8",
        "unitName": "市公安局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "credNum": "114400000069401674",
        "delFlag": "0",
        "type": "1",
        "unitCode": "z5N2zSetiup81QAJzok",
        "unitName": "市税务局"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "parentUnitCode": "sVmQT735qD3Rwyu9wit",
        "type": "2",
        "unitCode": "6lMMRgrf6OBXe68P8C2",
        "unitName": "研发事业部"
    },
    {
        "areaName": "广州市",
        "areaSeq": "nbaLYQdhotXvAs2QXaW",
        "delFlag": "0",
        "type": "1",
        "unitCode": "sVmQT735qD3Rwyu9wit",
        "unitName": "心猿码意软件"
    }
]
实现代码:
/**
 * <h2>窗口单位信息树</h2>
 * @author 心猿码意
 * @date 2023-04-25 18:23:21
 **/
@Data
public class WinUnitTreeVo implements Serializable {
    @ApiModelProperty(value = "所属地区名称")
    private List<WinUnitTreeVo> childUnit;
    @ApiModelProperty(value = "父级机构主键")
    private String parentUnitCode;
    @ApiModelProperty(value = "单位编号")
    private String unitCode;
    @ApiModelProperty(value = "单位名称")
    private String unitName;
}

@Data
public class PlatformUnitVo {

    /**
     * 所属单位主键
     */
    private String unitCode;

    /**
     * 部门名称
     */
    private String unitName;

    /**
     * 父级机构主键
     */
    private String parentUnitCode;

    /**
     * 是否主部门:0否,1是
     */
    private String defaultFlag;

    /**
     * 社会统一信用代码
     */
    private String credNum;

    /**
     * 删除状态:1删除,0否
     */
    private String delFlag;

    /**
     * 单位所属地区编码
     */
    private String areaSeq;

    /**
     * 单位所属地区名称
     */
    private String areaName;

    /**地区行政区划代码*/
    private String areaCode;

    /**
     * 父级地区主键
     */
    private String parentAreaSeq;

    /**
     * 父级地区名称
     */
    private String parentAreaName;

    /**
     * 组织机构类型(1:单位,2:部门)
     */
    private String type;

    /**
     * 附加属性值集合
     */
    private List<ExtraAttrVo> extraAttrs;
}
public List<WinUnitTreeVo> getWorkitemUnitList(String unitCodes) {
        List<PlatformUnitVo> platformUnitVos = "前面的json";
        List<WinUnitTreeVo> winUnitTreeVoList = new ArrayList<>();
        platformUnitVos.stream().forEach(vo ->{
            WinUnitTreeVo winUnitTreeVo = new WinUnitTreeVo();
            winUnitTreeVo.setUnitCode(vo.getUnitCode());
            winUnitTreeVo.setUnitName(vo.getUnitName());
            winUnitTreeVo.setParentUnitCode(vo.getParentUnitCode());
            winUnitTreeVoList.add(winUnitTreeVo);
        });
        List<String> ids = winUnitTreeVoList.stream().map(WinUnitTreeVo::getUnitCode).collect(Collectors.toList());
        List<WinUnitTreeVo> tree = new ArrayList<>();
        for (WinUnitTreeVo winUnitTreeVo : winUnitTreeVoList) {
            //找到根节点
            if (winUnitTreeVo.getParentUnitCode() == null || !ids.contains(winUnitTreeVo.getParentUnitCode())) {
                tree.add(findChildren(winUnitTreeVo, winUnitTreeVoList));
            }
        }
        return tree;
    }

    private WinUnitTreeVo findChildren(WinUnitTreeVo winUnitTreeVo, List<WinUnitTreeVo> list) {
        List<WinUnitTreeVo> children = new ArrayList<>();
        for (WinUnitTreeVo node : list) {
            if (StringUtils.isNotBlank(node.getParentUnitCode()) && node.getParentUnitCode().equals(winUnitTreeVo.getUnitCode())) {
                //递归调用
                children.add(findChildren(node, list));
            }
        }
        winUnitTreeVo.setChildUnit(children);
        return winUnitTreeVo;
    }
最终返回的单位树如下:
[
    {
        "queryType": null,
        "unitCode": "GEqONvGif1pkgeypVsW",
        "unitName": "广东省残疾人联合会",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": []
    },
    {
        "queryType": null,
        "unitCode": "27DYBhqxPhWkxyyShIZ",
        "unitName": "测试",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "5coZCC2viVbTAotmTIW",
                "unitName": "测试部门",
                "userCode": null,
                "parentUnitCode": "27DYBhqxPhWkxyyShIZ",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "N0mcwIHkncfZJG3jj0E",
        "unitName": "广东省教育厅",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "k2OHsF7ZnpYADkJbiGi",
                "unitName": "教育厅-1部门",
                "userCode": null,
                "parentUnitCode": "N0mcwIHkncfZJG3jj0E",
                "childUnits": []
            },
            {
                "queryType": null,
                "unitCode": "TLgo7tY9HbD9TMZqRxL",
                "unitName": "教育厅-1单位",
                "userCode": null,
                "parentUnitCode": "N0mcwIHkncfZJG3jj0E",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "pylto8i5gezxWPsLulf",
        "unitName": "广州市市场监督管理局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "dAVzZSmgFAuBhk05Tmw",
                "unitName": "审批科",
                "userCode": null,
                "parentUnitCode": "pylto8i5gezxWPsLulf",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "8wUPbECBVx75UqQ6gjM",
        "unitName": "文旅局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "1yfUGoRc0EVyejByf9a",
                "unitName": "市场处",
                "userCode": null,
                "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
                "childUnits": [
                    {
                        "queryType": null,
                        "unitCode": "iaqpYx0lUKzrum8oYMl",
                        "unitName": "事项测试部门43",
                        "userCode": null,
                        "parentUnitCode": "1yfUGoRc0EVyejByf9a",
                        "childUnits": []
                    }
                ]
            },
            {
                "queryType": null,
                "unitCode": "6DZWgfIUzHa0wk8ixKz",
                "unitName": "广东省人力资源和社会保障厅",
                "userCode": null,
                "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
                "childUnits": [
                    {
                        "queryType": null,
                        "unitCode": "FMZpUJ3fCtnllZAAXPT",
                        "unitName": "测试部门-2-1",
                        "userCode": null,
                        "parentUnitCode": "6DZWgfIUzHa0wk8ixKz",
                        "childUnits": []
                    }
                ]
            },
            {
                "queryType": null,
                "unitCode": "hMAxUNUDfBdlRT6P5NT",
                "unitName": "文物局",
                "userCode": null,
                "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
                "childUnits": []
            },
            {
                "queryType": null,
                "unitCode": "xWKRcZWjYTtuy5gMqmq",
                "unitName": "审核处",
                "userCode": null,
                "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
                "childUnits": [
                    {
                        "queryType": null,
                        "unitCode": "P0ZjaRLjCaTmk1vCs0t",
                        "unitName": "事项测试子部门",
                        "userCode": null,
                        "parentUnitCode": "xWKRcZWjYTtuy5gMqmq",
                        "childUnits": []
                    }
                ]
            },
            {
                "queryType": null,
                "unitCode": "PCkQHkCqBQ8G433PlpN",
                "unitName": "准入处",
                "userCode": null,
                "parentUnitCode": "8wUPbECBVx75UqQ6gjM",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "rBzaXFIRKovid7dgbyY",
        "unitName": "密码局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "KZlSpr0M9svbTxswtVp",
                "unitName": "001部门",
                "userCode": null,
                "parentUnitCode": "rBzaXFIRKovid7dgbyY",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "EG3iCBPm7bldC2esW1f",
        "unitName": "市民政局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "RmCztFLB1Ip4Tl0Lcyk",
                "unitName": "hello单位-1001部门",
                "userCode": null,
                "parentUnitCode": "EG3iCBPm7bldC2esW1f",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "wl4XDGhZg71ntFXT8aL",
        "unitName": "市医保局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "l29g1aszyjTCLmGgKMU",
                "unitName": "one测试部门",
                "userCode": null,
                "parentUnitCode": "wl4XDGhZg71ntFXT8aL",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "t9nq70CPS9PCwrL7ury",
        "unitName": "市人社局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "IA6mo3clsYao9qRqVKB",
                "unitName": "测试单位4-部门2",
                "userCode": null,
                "parentUnitCode": "t9nq70CPS9PCwrL7ury",
                "childUnits": []
            },
            {
                "queryType": null,
                "unitCode": "wBaWrcxKXAORTsr7PXr",
                "unitName": "测试单位4-部门1",
                "userCode": null,
                "parentUnitCode": "t9nq70CPS9PCwrL7ury",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "yK78GEa2MyLoTsv7cl8",
        "unitName": "食药监局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "oL5ku79eKjSD3wsonE2",
                "unitName": "测试单位3-部门2",
                "userCode": null,
                "parentUnitCode": "yK78GEa2MyLoTsv7cl8",
                "childUnits": []
            },
            {
                "queryType": null,
                "unitCode": "NZ7nrjiR2Ipp4jUvwdg",
                "unitName": "测试单位3-部门1",
                "userCode": null,
                "parentUnitCode": "yK78GEa2MyLoTsv7cl8",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "rdF29TiDg8A6uAhtwy8",
        "unitName": "市公安局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "iAeyIFab9QYfW1qnqIB",
                "unitName": "测试单位2-部门2",
                "userCode": null,
                "parentUnitCode": "rdF29TiDg8A6uAhtwy8",
                "childUnits": []
            },
            {
                "queryType": null,
                "unitCode": "4AE4Eec19qlquekC67b",
                "unitName": "测试单位2-部门1",
                "userCode": null,
                "parentUnitCode": "rdF29TiDg8A6uAhtwy8",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "z5N2zSetiup81QAJzok",
        "unitName": "市税务局",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "PqIu1vdrPEMcgw9QLil",
                "unitName": "测试单位-部门2",
                "userCode": null,
                "parentUnitCode": "z5N2zSetiup81QAJzok",
                "childUnits": []
            },
            {
                "queryType": null,
                "unitCode": "IyfejZ9DXBX24OararK",
                "unitName": "测试单位-部门1",
                "userCode": null,
                "parentUnitCode": "z5N2zSetiup81QAJzok",
                "childUnits": []
            }
        ]
    },
    {
        "queryType": null,
        "unitCode": "sVmQT735qD3Rwyu9wit",
        "unitName": "心猿码意软件",
        "userCode": null,
        "parentUnitCode": null,
        "childUnits": [
            {
                "queryType": null,
                "unitCode": "6lMMRgrf6OBXe68P8C2",
                "unitName": "研发事业部",
                "userCode": null,
                "parentUnitCode": "sVmQT735qD3Rwyu9wit",
                "childUnits": []
            }
        ]
    }
]

到了这里,关于包含了父子关系的单位对象的List数据转成树状结构的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Unity 组件 Constraint系列(不用设置父子关系模拟设置父子关系的操作)

    目录 目录 组件设置分析 Aim Constraints  Parent Constraints 小结 概要 Constraint组件可以约束物体,链接本物体与目标物体的Transform,跟随目标物体的位置、旋转、缩放,实现父子物体一样的效果,却不用设置父子关系。而且一个物体可以同时关联多个目标物体,设置不同的权重 A

    2024年02月03日
    浏览(38)
  • 【flask sqlalchmey】一次性将返回的列表对象或者 一行数据对象转成dict---flask-sqlalchemy输出json格式数据

    结果示例: 另外: res = Sysdict.query.all() 这种写法已经不被推荐了, 推荐的是scalar_one() 获取一行,scalars()获取多行 user = db.session.execute(db.select(User).filter_by(username=username)).scalar_one() users = db.session.execute(db.select(User).order_by(User.username)).scalars() 一般的 json.dumps(users) 或者 jsonify(use

    2024年02月13日
    浏览(52)
  • Java8 List<Object> 转成 List<JSONObject>

       Java8 List<Object> 转成 List<Map<String, Object>>

    2024年02月16日
    浏览(38)
  • java 把list转成json

    在Java中,将List转换成JSON格式是非常常见的任务。JSON是一种轻巧的数据交换格式,非常适合于Web应用程序,特别是前端开发。 使用Java将List转换成JSON格式的最简单方法是通过JSON库。最常用的JSON库是 Jackson,它提供了快速,灵活和易于使用的API来将Java对象转换为JSON格式。

    2024年02月07日
    浏览(39)
  • 【Unity】Transform—用代码设置父子关系

    子对象在世界坐标系下的位置是加法运算:子对象在世界坐标系下的位置 = 子对象的位置 + 父对象的位置 子对象在世界坐标系下的缩放是乘法运算:子对象在世界坐标系下的位置 = 子对象的位置 + 父对象的位置 现有: Lesson9脚本中的代码: 运行: 现有: Lesson9脚本的代码:

    2024年02月12日
    浏览(40)
  • 【Linux】进程的基本属性|父子进程关系

    个人主页:🍝在肯德基吃麻辣烫 我的gitee:Linux仓库 个人专栏:Linux专栏 分享一句喜欢的话:热烈的火焰,冰封在最沉默的火山深处 本篇文章继上文的进程概念后,现在对进程概念有了一定的理解。前面说过,操作系统管理进程实际上是管理描述进程的 PCB对象 ,而PCB对象是

    2024年02月12日
    浏览(40)
  • java切割字符串,转成list

    因项目需求,需要对前端传过来的字符串进行切割操作,记录下来,以便后续查看。

    2024年02月07日
    浏览(59)
  • <List<Map<String,Object>>>Map中多个属性转成List Map

    举例: 原始数据 :{001=张三, 002=李四, 003=王五, 004=赵六} 目标数据 : {value=张三, key=001} {value=李四, key=002} {value=王五, key=003} {value=赵六, key=004} 输出: 单独封装工具类案例:

    2024年02月11日
    浏览(43)
  • java中Stream转成List类型如下写代码?

    在Java中,将Stream转换为List类型可以使用 Collectors.toList() 方法。以下是示例代码: javaCopy code import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class StreamToListExample { public static void main(String[] args) { StreamInteger stream = Stream.of(1, 2, 3, 4, 5); ListInteger list = str

    2024年02月12日
    浏览(55)
  • 【PyQt学习篇 · ⑦】:QWidget - 父子关系扩充和层级控制

    childAt(x, y) 函数可以根据传入的坐标参数获取该QWidget中位于该坐标位置的子QWidget,如果该位置没有子QWidget则返回None。 parentWidget() 函数可以获取当前QWidget的父QWidget,如果没有父QWidget则返回None。通过这个函数可以遍历组成QWidget树的所有QWidget。 childrenRect() 函数可以获取该Q

    2024年02月07日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包