1.查询一个分类的完整分类路径并返回成数组例如[2,48,168]
// [2,48,168]
public long[] findCatelogPath(Long catelogId){
// 要返回的结果集合 2,48,168
ArrayList<Long> path = new ArrayList<>;
List<Long> parentPath = findParentPath(catelogId, path);
// 数组转成集合
return parentPath.toArray(new Long[parentPath.size()]);
}
// 168,48,2
private List<Long> findParentPath(Long catelogId, List<Long> path){
path.add(catelogId);
CategoryEntity categoryEntity = this.getById(catelogId);
// 还有父分类
if(categoryEntity.getParentCid != 0) {
findParentPath(categoryEntity.getParentCid,path);
}
return path;
}