List<SysRouter> sysRouters = queryAll();
TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
// 自定义属性名 都有默认值的哈
// 默认支持排序
treeNodeConfig.setWeightKey("orderNum");
treeNodeConfig.setChildrenKey("children");
//可配置树深度
treeNodeConfig.setDeep(2);
treeNodeConfig.setIdKey("id");
//转换器
List<Tree<String>> build = TreeUtil.build(sysRouters, "0", treeNodeConfig,
(treeNode, tree) -> {
tree.setId(treeNode.getId().toString());
tree.setParentId(treeNode.getParentId().toString());
tree.setWeight(treeNode.getOrderNum());
tree.setName(treeNode.getName());
// 扩展属性
tree.putExtra("path", treeNode.getPath());
tree.putExtra("hasClassify", treeNode.getHasClassify());
});
return build;
网友评论