100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > JAVA树状结构转List平面

JAVA树状结构转List平面

时间:2019-08-22 12:09:58

相关推荐

JAVA树状结构转List平面

JAVA树状结构转List平面

使用递归实现

#主方法A 实体,@ApiModel(value = "A", description = "信息")@Datapublic class A{@ApiModelProperty(value = "级别,从1开始")private String level;@ApiModelProperty(value = "父节点编码")@Size(max = 30)@NotNullprivate String parentNode ;@ApiModelProperty(value = "子节点集合")@ValidList<A> children;}

##实现类//树转list List<A> needSaveList = new ArrayList<>(16);//递归createBodNodeList(needSaveList, null, X.getChildren(), 0);

/*** 树转list*/private void createBodNodeList(List<A> needSaveList, BodNodesAdd parentNode, List<A> children, int level, String bodNo) {if (children == null || children.size() == 0) {return;}level++;for (A inWarehouse : children) {A needSaveNode= BeanUtils.convert(inWarehouse, A.class);needSaveNode.setParentNodeNo(parentNode == null ? "" : parentNode.getNodeNo());needSaveNode.setLevel(level);needSaveList.add(needSaveBodNode);createBodNodeList(needSaveList, inWarehouse, inWarehouse.getChildren(), level);}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。