稍等
import java.util.ArrayList;
import java.util.List;
public class Bean
{
private int id;
private int pid;
private String text;
private String url;
private Bean parent;
private List<Bean> children = new ArrayList<Bean>();
、、、、自己生成getset方法,超长了
public static void main(String[] args)
{
//取一堆数据,是吧。。。
List<Bean> list = new ArrayList<Bean>();
//建立关系咯
Bean.createTree(list);
//如果有的话
Bean bean = list.get(0);
List<Bean> children2 = bean.getChildren();
}
public static void createTree(List<Bean> bean)
{
if (null == bean)
{
return ;
}
for (Bean each : bean)
{
for (Bean inner : bean)
{
if (each.getId() == inner.getPid())
{
each.getChildren().add(inner);
inner.setParent(each);
}
}
}
}
}