java 递归获取所有的层级关系

public JSONArray getJsonArray(JSONArray array,DamsEquipmentModel destDams){
    destDams.setIsDelete(Constants.ZERO);
    List damsEquipmentModels = getDao().getList(destDams);
    if(damsEquipmentModels!=null){
            damsEquipmentModels.forEach((damsEquipmentPropertyVo) -> {
                JSONObject obj = new JSONObject();
                DamsEquipmentModel damsEquipmentModel1=new DamsEquipmentModel();
                damsEquipmentModel1.setParentId(damsEquipmentPropertyVo.getId());
                obj.put("id", damsEquipmentPropertyVo.getId());
                obj.put("name", damsEquipmentPropertyVo.getNodeName());
                obj.put("collapsed", false);
                obj.put("children", getJsonArray(new JSONArray(),damsEquipmentModel1));
                array.add(obj);
            });
    }
    return array;
}

你可能感兴趣的:(java 递归获取所有的层级关系)