1. 第一种菜单树结构
package com.xiaolh.dao.util;
import com.xiaolh.dao.model.MenuTree;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* TSysPower树工具类
* </p>
*
* @author: xiaolh
* @email: amixiao@qq.com
* @createTime: 2021/3/16 09:53
*/
public abstract class TreeUtil {
private static final Integer TOP_NODE_ID = 0;
public static <T> MenuTree<T> buildMenuTree(List<MenuTree<T>> nodes) {
if (nodes == null) {
return null;
}
//得到父菜单
List<MenuTree<T>> topNodes = new ArrayList<>();
nodes.forEach(children -> {
//得到子菜单的父菜单id
Integer pid = children.ge