基本思想
根据根节点没有父节点原理找到父节点;
根据子节点的父id找到根节点所有的子节点;
递归遍历父节点的所有子节点;
private void recursionFn(List<SysDept> list, SysDept t)
{
// 得到子节点列表
List<SysDept> childList = getChildList(list, t);
t.setChildren(childList);
for (SysDept tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
private List<SysDept> getChildList(List<SysDept> list, SysDept t)
{
List<SysDept> tlist = new ArrayList<SysDept>();
Iterator<SysDept> it = list.iterator();
while (it.hasNext())
{
SysDept n = (SysDept) it.next();
// 子节点的父id
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
{
tlist.add(n);
}
}
return tlist;
}
标签:SysDept,递归函数,tChild,List,list,列表,树形,childList,节点 From: https://www.cnblogs.com/ReturnOfTheKing/p/18066389