大家如果感兴趣可以放问这个网址
http://www.ybloy.com/post/2009/07/16/Liste98092e5bd92e7949fe68890e4b88be68b89e58897e8a1a8e6a091.aspx
里面有实现过后的效果和代码的注释。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
javaCode
1
//=================begin-取得类型树=================
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
private List<SysAuditotypecategory> cTreeList(List<SysAuditotypecategory> aList)
{
3
List<SysAuditotypecategory> returnList = new ArrayList<SysAuditotypecategory>();
4
List<SysAuditotypecategory> topList = new ArrayList<SysAuditotypecategory>();
5
List<SysAuditotypecategory> tempList = new ArrayList<SysAuditotypecategory>();
6![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (SysAuditotypecategory sacty : aList)
{
8![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(sacty.getParent()==null)
{
9
topList.add(sacty);
10![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
11
tempList.add(sacty);
12
}
13
}
14![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for (int i=0;i<topList.size();i++)
{
16
SysAuditotypecategory sacty = topList.get(i);
17
returnList.add(cTreeNode(sacty, "", (i+1<topList.size())));
18
returnList.addAll(cTreeNodeList(tempList,sacty.getId(),(i+1<topList.size())?"│":" "));
19
}
20
return returnList;
21
}
22![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
private List<SysAuditotypecategory> cTreeNodeList(List<SysAuditotypecategory> inList,Long parentid,String headString)
{
24
List<SysAuditotypecategory> tempList1 = new ArrayList<SysAuditotypecategory>();
25
List<SysAuditotypecategory> tempList2 = new ArrayList<SysAuditotypecategory>();
26
List<SysAuditotypecategory> returnList = new ArrayList<SysAuditotypecategory>();
27![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(int i=0;i<inList.size();i++)
{
29
SysAuditotypecategory sacty = inList.get(i);
30![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(sacty.getParent().getId() == parentid)
{
31
tempList1.add(sacty);
32![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else
{
33
tempList2.add(sacty);
34
}
35
}
36![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(tempList1.size()>0)
{
38![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
for(int i=0;i<tempList1.size();i++)
{
39
SysAuditotypecategory sacty1 = tempList1.get(i);
40
returnList.add(cTreeNode(sacty1, headString, (i+1<tempList1.size())));
41![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
42![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(tempList2.size()>0)
{
43
returnList.addAll(cTreeNodeList(tempList2,sacty1.getId(),headString+((i+1<tempList1.size())?"│":" ")));
44
}
45
}
46
}
47![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
return returnList;
49
}
50![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
51![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
private SysAuditotypecategory cTreeNode(SysAuditotypecategory satcy,String headString,boolean havenext)
{
52
satcy.setCategoryname(headString.concat((havenext?"├":"└"))+satcy.getCategoryname());
53
return satcy;
54
}