9.返回完整路径
作者:互联网
//[2,29,20]
@Override
public Long[] findCatelogPath(Long catelogId) {
List<Long> paths = new ArrayList<>();
//递归查询是否还有父节点
List<Long> parentPath = findParentPath(catelogId, paths);
//进行一个逆序排列
Collections.reverse(parentPath);
return (Long[]) parentPath.toArray(new Long[parentPath.size()]);
}
private List<Long> findParentPath(Long catelogId, List<Long> paths) {
//1、收集当前节点id
paths.add(catelogId);
//根据当前分类id查询信息
CategoryEntity byId = this.getById(catelogId);
//如果当前不是父分类
if (byId.getParentCid() != 0) {
findParentPath(byId.getParentCid(), paths);
}
return paths;
}
标签:返回,paths,路径,List,Long,完整,catelogId,parentPath,byId 来源: https://www.cnblogs.com/55zjc/p/15970993.html