用户controller
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
UserService userService;
@Autowired
CategoryService categoryService;
// @Autowired
// CategoryService categoryService;
@GetMapping("/findUser")
@ResponseBody
public User findUser(){
return userService.findUser();
}
@ApiOperation("后台数据列出商品目录,给用户看")
@PostMapping("/listCategoryForUser")
public ApiResponseObj listCategoryForUser(){
List<CategoryVO> categoryVOS = categoryService.listForUser();
return ApiResponseObj.success(categoryVOS);
}
category的实现类
@Override
public List<CategoryVO> listForUser(){
ArrayList<CategoryVO> arrayList = new ArrayList<>();
System.out.println(arrayList.toString());
// 调用下面的递归查询方法
recursiveFindCategory(0,arrayList);
System.out.println(arrayList.toString());
return arrayList;
}
private void recursiveFindCategory(Integer parentId,List<CategoryVO> categoryVOList){
//手写mapper的查询selectByParentId
List<Category> categoryList = categoryMapper.selectByParentId(parentId);
//判断categoryList是不是空
// categoryList ==null,这样子判断不够全面
// CollectionUtils.isEmpty()的方法判断更全面,return collection == null || collection.isEmpty();
if(!CollectionUtils.isEmpty(categoryList)){
for (int i = 0; i < categoryList.size(); i++) {
Category category = categoryList.get(i);
CategoryVO categoryVO = new CategoryVO();
BeanUtils.copyProperties(category,categoryVO);
// categoryList.add(categoryVO);
categoryVOList.add(categoryVO);
recursiveFindCategory(categoryVO.getId(),categoryVO.getChildCategory());
}
}
mapper
<select id="selectByParentId" parameterType="integer" resultMap="BaseResultMap">
select <include refid="Base_Column_List"></include>
from imooc_mall_category
where parent_id=#{parentId}
</select>
测试失败404,请问啥原因?
"timestamp": "2023-02-09T05:15:08.214+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/user/listCategoryForUser"
}
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星