接口返回数据时,临时封装特定格式返回

  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;
    }

 

posted @ 2021-12-02 11:44  阿旭92312  阅读(31)  评论(0编辑  收藏  举报