通常在对商品分类的时候会进行分类筛选:
调用:
/**
* 递归查询当前节点的id及子节点的id
* @param categoryId
* @return
*/
@Override
public Response selectCategoryAndChildrenById(Integer categoryId) {
Set<Category> categorySet = Sets.newHashSet();
// 方式一
// findChildCategory( categorySet, categoryId);
// 方式二
List<Category> categoryList1 = categoryDao.selectAll();
findChildCategory( categorySet, categoryList1, categoryId);
List<Integer> categoryList = Lists.newArrayList();
if (categoryId != null){
for (Category category : categorySet){
categoryList.add(category.getId());
}
}
return Response.success(categoryList);
}
递归方式一
// 递归算法,算出子节点 (个人觉得不好)
private Set<Category> findChildCategory(Set<Category> categorySet,Integer categoryId){
Category category = categoryDao.selectByPrimaryKey(categoryId);
if (category != null){