记录一次调Bug

Bug是这样的,有一个通过id列表删除对象的接口,正确的代码是这样的:

/*url: `${api_name}/batchRemove`,
    method: 'delete',
    data: idList*/
    @ApiOperation("根据id列表删除商品分类")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids){
        boolean b = categoryService.removeByIds(ids);
        if (b){
            return Result.ok(null);
        }else {
            return Result.fail(null);
        }
    }

如果写成这样:

/*url: `${api_name}/batchRemove`,
   method: 'delete',
   data: idList*/
   @ApiOperation("根据id列表删除商品分类")
   @DeleteMapping("/batchRemove")
   public Result batchRemove(@RequestBody List<Category> ids){
       boolean b = categoryService.removeByIds(ids);
       if (b){
           return Result.ok(null);
       }else {
           return Result.fail(null);
       }
   }

List<>尖括号里面的对象传错了,前端传过来数据就会报这样的错:
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of com.atguigu.ssyx.model.product. Category (although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (11);

1.写代码的时候头脑一定要清醒
2.多用Swagger等测试文档,很容易找到问题出在哪里
3.多用F12网络模块排查

你可能感兴趣的:(bug,java,开发语言)