介面返回資料時,臨時封裝特定格式返回
阿新 • • 發佈:2021-12-02
public List<JSONObject> getDictTree(String remarks) { List<JSONObject> tree = new ArrayList<>(); List<SysDict> list=sysDictRepository.getAllByRemarksAndIsEnableAndDelFlag(remarks,"1", Constants.DELETE_DEFAULT); for (SysDict dic : list) { JSONObject parent= new JSONObject(); parent.put("label",dic.getLabel()); parent.put("id",dic.getId()); //獲取一級節點的子節點 List<SysDictContent> children = sysDictContentRepository.findAllByParentId(dic.getId()); List<JSONObject> childrenList = new ArrayList<>();if(children!=null && !children.isEmpty()){ for (SysDictContent child : children) { JSONObject childJson = new JSONObject(); childJson.put("label",child.getLabel()); childJson.put("id",child.getId()); childrenList.add(childJson); } parent.put("children",childrenList); } tree.add(parent); } return tree; }