mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 02:08:15 +08:00
Pre Merge pull request !140 from HuangXin/N/A
This commit is contained in:
commit
f17b8da152
@ -122,5 +122,15 @@ public interface Constants {
|
||||
*/
|
||||
String SYS_DICT_KEY = "sys_dict:";
|
||||
|
||||
/**
|
||||
* Long数据类型默认根节点
|
||||
*/
|
||||
Long LongRootId = 0L;
|
||||
|
||||
/**
|
||||
* String数据类型默认根节点
|
||||
*/
|
||||
String StringRootId = "0";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNodeConfig;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.lang.tree.parser.NodeParser;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ -22,7 +24,37 @@ public class TreeBuildUtils extends TreeUtil {
|
||||
*/
|
||||
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) {
|
||||
// 默认设为根节点
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user