java Tree结构数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mbh12333/article/details/84343740
@Override
    public List<BaseZTree> getTemplateData(){
        List<BaseZTree> queryList = getDirectory("-1",false);
        List<BaseZTree> parentList = new ArrayList<>();
        for (BaseZTree baseZTree : queryList) {
            if (StringUtils.isBlank(baseZTree.getpId())) {
                parentList.add(baseZTree);
            }
        }
        recursionChildren(parentList, queryList);
        return parentList;
    }

    private void recursionChildren(List<BaseZTree> parentList, List<BaseZTree> allList) {
        for (BaseZTree parentBaseZTree : parentList) {
            List<BaseZTree> childrenList = new ArrayList<>();
            for (BaseZTree baseZTree : allList) {
                if (baseZTree.getpId().equals(parentBaseZTree.getId())) {
                    childrenList.add(baseZTree);
                }
            }
            if (ObjectUtil.isNotNull(childrenList)) {
                parentBaseZTree.setChildren(childrenList);
                recursionChildren(childrenList, allList);
            }
        }
    }
**
 * ztree 结构 实体类
 * @author mbh
 * @date 2018/10/16 15:40
 */
public class BaseZTree {
    private String id;
    private String pId;
    private String name;
    private String text;
    private String nodeType;
    private boolean isParent;
    private boolean open;
    private List<BaseZTree> children = new ArrayList<>();
    private int position;

    public BaseZTree() {
    }

    public BaseZTree(String id, String name) {
        this.id = id;
        this.name = name;
    }

    /**
     * 节点其他属性,传递其他属性zTree控件需要这样配置
     */
    private Map<String, String> attributes = new HashMap<String, String>();
    //private List<TPln6Flow> children = new ArrayList<TPln6Flow>();
    private String icon;
    private boolean nocheck;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

//    public List<TPln6Flow> getChildren() {
//        return children;
//    }
//
//    public void setChildren(List<TPln6Flow> children) {
//        this.children = children;
//    }


    public List<BaseZTree> getChildren() {
        return children;
    }

    public void setChildren(List<BaseZTree> children) {
        this.children = children;
    }

    public Map<String, String> getAttributes() {
        return attributes;
    }

    public void setAttributes(Map<String, String> attributes) {
        this.attributes = attributes;
    }

    public String getNodeType() {
        return nodeType;
    }

    public void setNodeType(String nodeType) {
        this.nodeType = nodeType;
    }

    public boolean getIsParent() {
        return isParent;
    }

    public void setIsParent(boolean isparent) {
        isParent = isparent;
    }

    public boolean getOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getpId() {
        return pId;
    }

    public void setpId(String pId) {
        this.pId = pId;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public boolean isNocheck() {
        return nocheck;
    }

    public void setNocheck(boolean nocheck) {
        this.nocheck = nocheck;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public void addChildren(BaseZTree baseZTree) {
        List<BaseZTree> nodes = this.getChildren();
        if (nodes == null) {
            List<BaseZTree> list = new ArrayList<>();
            list.add(baseZTree);
            this.setChildren(list);
        }else{
            nodes.add(baseZTree);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/mbh12333/article/details/84343740