cn.smallbun.scaffold.framework.mybatis.utils.NodeHelp Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2018-2019.[zuoqinggang] www.pingfangushi.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package cn.smallbun.scaffold.framework.mybatis.utils;
import cn.smallbun.scaffold.framework.mybatis.domain.BaseNodeEntity;
import com.google.common.collect.Lists;
import org.springframework.util.CollectionUtils;
import java.io.Serializable;
import java.util.List;
/**
* 节点工具类
* @author SanLi
* Created by [email protected] / [email protected] on 2019/10/11 20:28
*/
public class NodeHelp implements Serializable {
/**
* 获取树
* @param list list
* @param 类型
*/
public static > List getNodeList(List list) {
if (!CollectionUtils.isEmpty(list)) {
for (T li : list) {
List ts = Lists.newArrayList();
//设置子菜单
for (T entity : list) {
//子节点和父节点不一致
if (!li.getId().equals(entity.getId())
//父节点等于子节点
&& li.getId().equals(entity.getParentId())) {
ts.add(entity);
li.setChildren(ts);
//如果已经成为了子节点,设置状态
entity.setLeaf(true);
}
}
}
list.removeIf(T::isLeaf);
return list;
}
return Lists.newArrayList();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy