引入依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.2</version>
</dependency>
//查询出数据
List<CompanyInfo> companyInfos = companyInfoMapper.selectList(Wrappers.<CompanyInfo>query().lambda()
.eq(CompanyInfo::getFlagDisabled, "Y"));
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
//最大递归深度
treeNodeConfig.setDeep(3);
//转换器
List<Tree<String>> trees = TreeUtil.build(companyInfos, "0", treeNodeConfig, (treeNode, tree) -> {
tree.setId(treeNode.getPosid());
tree.setParentId(treeNode.getParentId());
//拓展属性
tree.putExtra("name", treeNode.getProName());
});