mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 10:13:28 +08:00
系统树构建工具类添加默认根节点,以及添加字符串类型的树型结构方法
This commit is contained in:
parent
e2b786d97b
commit
aea1887a41
@ -122,5 +122,15 @@ public interface Constants {
|
|||||||
*/
|
*/
|
||||||
String SYS_DICT_KEY = "sys_dict:";
|
String SYS_DICT_KEY = "sys_dict:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Long数据类型默认根节点
|
||||||
|
*/
|
||||||
|
Long LongRootId = 0L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String数据类型默认根节点
|
||||||
|
*/
|
||||||
|
String StringRootId = "0";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package com.ruoyi.common.utils;
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Validator;
|
||||||
import cn.hutool.core.lang.tree.Tree;
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||||
import cn.hutool.core.lang.tree.TreeUtil;
|
import cn.hutool.core.lang.tree.TreeUtil;
|
||||||
import cn.hutool.core.lang.tree.parser.NodeParser;
|
import cn.hutool.core.lang.tree.parser.NodeParser;
|
||||||
|
import com.ruoyi.common.constant.Constants;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@ -22,7 +24,37 @@ public class TreeBuildUtils extends TreeUtil {
|
|||||||
*/
|
*/
|
||||||
public static final TreeNodeConfig DEFAULT_CONFIG = TreeNodeConfig.DEFAULT_CONFIG.setNameKey("label");
|
public static final TreeNodeConfig DEFAULT_CONFIG = TreeNodeConfig.DEFAULT_CONFIG.setNameKey("label");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建整型类型的树型结构
|
||||||
|
* @param list 数据列表
|
||||||
|
* @param parentId 父级ID
|
||||||
|
* @param nodeParser 节点解析
|
||||||
|
* @param <T> 实体
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static <T> List<Tree<Long>> build(List<T> list, Long parentId, NodeParser<T, Long> nodeParser) {
|
public static <T> List<Tree<Long>> build(List<T> list, Long parentId, NodeParser<T, Long> nodeParser) {
|
||||||
|
// 默认设为根节点
|
||||||
|
if (Validator.isNull(parentId)) {
|
||||||
|
parentId = Constants.LongRootId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TreeUtil.build(list, parentId, DEFAULT_CONFIG, nodeParser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建字符串类型的树型结构
|
||||||
|
* @param list 数据列表
|
||||||
|
* @param parentId 父级ID
|
||||||
|
* @param nodeParser 节点解析
|
||||||
|
* @param <T> 实体
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> List<Tree<String>> buildStrTree(List<T> list, String parentId, NodeParser<T, String> nodeParser) {
|
||||||
|
// 默认设为根节点
|
||||||
|
if (Validator.isEmpty(parentId)) {
|
||||||
|
parentId = Constants.StringRootId;
|
||||||
|
}
|
||||||
|
|
||||||
return TreeUtil.build(list, parentId, DEFAULT_CONFIG, nodeParser);
|
return TreeUtil.build(list, parentId, DEFAULT_CONFIG, nodeParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user