1、Entity(实体类)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RegionTree {
private String id;
private String parentId;
private List<RegionTree> children;
}
2、TreeUtils
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class TreeUtil {
public static List<RegionTree> tree(List<RegionTree> regionTrees) {
List<RegionTree> rootNodes = new ArrayList<>();
Iterator<RegionTree> it = regionTrees.iterator();
while (it.hasNext()) {
RegionTree next = it