在对商品进行分类时,类别表会出现父节点
![](https://img-blog.csdn.net/20180924191929331?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0lUdzMzMw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
递归查询本节点的id及孩子节点的id
/**
* 递归查询本节点的id及孩子节点的id
* @param categoryId
* @return
*/
public ServerResponse<List<Integer>> selectCategoryAndChildrenById(Integer categoryId){
Set<Category> categorySet = Sets.newHashSet();
findChildCategory(categorySet,categoryId);
List<Integer> categoryIdList = Lists.newArrayList();
if(categoryId != null){
for(Category categoryItem : categorySet){
categoryIdList.add(categoryItem.getId());
}
}
return ServerResponse.createBySuccess(categoryIdList);
}
//递归算法,算出子节点
private Set<Category> findChildCategory