JAVA树状结构转List平面
使用递归实现
#主方法
A 实体,
@ApiModel(value = "A", description = "信息")
@Data
public class A{
@ApiModelProperty(value = "级别,从1开始")
private String level;
@ApiModelProperty(value = "父节点编码")
@Size(max = 30)
@NotNull
private String parentNode ;
@ApiModelProperty(value = "子节点集合")
@Valid
List<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) {