使用hutool中的树形结构api时自定义扩展属性

使用hutool的树结构工具时,其内置的TreeNode类只有固定的几个属性,想添加自定义属性怎么办?

文档中给出了自定义字段名的方法,但是自定义的字段名还是不能从每个TreeNode结点中获取

 

 我的解决方法是新建一个结点类继承TreeNode,添加自定义属性,并实现构造方法

@Data
public class LayerTopicTreeNode extends TreeNode<String> {

    private String code;
    private String name;
    private Integer weight;
    private String description;
    private String icon;
    private String pCode;
    private Integer resourceCount;

    public LayerTopicTreeNode(){}

    public LayerTopicTreeNode(String code,String name,String description,String icon,String pCode,Integer resourceCount,Integer weight){
        super(code,pCode,name,weight);
        this.code = code;
        this.name = name;
        this.weight = weight;
        this.description = description;
        this.icon = icon;
        this.pCode = pCode;
        this.resourceCount = resourceCount;
    }

}

 

 在添加结点集合时使用自定义的这个节点类

 

 这样在构建时就可以从node结点中获取自定义的字段值

 

Guess you like

Origin blog.csdn.net/qq_41890624/article/details/120737749