for (CategoryVo categoryVo : categoryVoList) {
List<CategoryVo> subCategoryVoList = new ArrayList<>();
for (Category category : categories) {
//如果查到内容,设置subCategory,继续往下查
if (categoryVo.getId().equals(category.getParentId())) {
CategoryVo subcategoryVo = category2CategoryVo(category);
subCategoryVoList.add(subcategoryVo);
}
}
categoryVo.setSubCategories(subCategoryVoList);
}
老师,categoryVo.setSubCategories(subCategoryVoList);这一句是不是应该写在内层for循环的外面?因为SubCategories应该是直接添加所有子类目的list。
再就是我发现写在里面和外面结果一样,这是为啥?