汤阳光OA视频中使用递归展现添加与修改页面中的树状上级部门列表

来源:互联网 发布:欧洲篮球冠军联赛数据 编辑:程序博客网 时间:2024/04/29 20:07
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;


import com.wuyi.oa.domain.Department;


public class DepartmentUtils
{
/**
* 遍历部门树,把所有的部门遍历出来放到同一个集合当中返回,并且其中所有部门的名称都修改了,以表示层次
* @param topList
* @return
*/
public static List<Department> getAllDepartments(List<Department> topList)
{
List<Department> list = new ArrayList<Department>();
walkDepartmentTreeList(topList,"┠",list);

return list;
}
/**
* 遍历部门树,把遍历出的部门信息放到指定的集合中
* @param topList
*/
private static void walkDepartmentTreeList(Collection<Department> topList,String prefix,List<Department> list)
{
for(Department top : topList)
{
//顶点
//System.out.println(top.getName());
top.setName(prefix + top.getName());
list.add(top);

//子树
walkDepartmentTreeList(top.getChildren()," "+prefix,list);//使用全角的空格
}

}

}
0 0
原创粉丝点击