首页>代码>ssm商品后台管理系统>/trade/src/main/java/com/auth/common/tree/Tree.java
package com.auth.common.tree;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import com.auth.entity.Function;


public class Tree {
	private List<Node> nodes=new LinkedList();
	private Node root=null;
	public Tree(List<Function> functions){
		for(Function function:functions){
			Node node=new Node(function.getId(),function.getParentId(),function.getName(),"open",new NodeAttribute(null==function.getUrl()?"":function.getUrl(),function.getId()),function.getSerialNum());
			nodes.add(node);
			if(node.getParentId()==-1){//菜单树根节点
				root=node;
			}

		}
	}
	
	public List<Node> build(){
		buildTree(root);
		List<Node> result=new ArrayList<Node>();
		result.add(root);
		return result;
	}
	
	public void buildTree(Node parent){
		Node node=null;
		for(Iterator<Node> ite=nodes.iterator();ite.hasNext();){
			node=ite.next();
			if(node.getParentId()!=null && node.getParentId().equals(parent.getId())){
				parent.getChildren().add(node);
				buildTree(node);
			}
		}
	}
	
	
	
	
	
}
最近下载更多
xiaoaitx  LV8 1月2日
lxzlxzl  LV1 2024年6月21日
xhqxhq  LV1 2024年6月6日
yangxinyullll  LV1 2024年4月28日
微信网友_6512020493586432  LV2 2024年4月8日
xiongM  LV4 2024年4月4日
wangsheng818  LV4 2024年2月28日
马宇轩  LV1 2023年11月19日
泓鼎168  LV20 2023年10月16日
1257592068  LV6 2023年6月6日
最近浏览更多
longouxiu 3月1日
暂无贡献等级
xiaoaitx  LV8 1月1日
zhoubowen  LV3 2024年12月28日
xiuele 2024年12月26日
暂无贡献等级
三秋桂子  LV1 2024年12月21日
taoshen95  LV16 2024年12月21日
按市场洒出C  LV1 2024年12月8日
shunlun8855  LV1 2024年10月29日
lz88888  LV12 2024年10月18日
zhengguangshun  LV4 2024年8月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友