我们设计接口的时候,往往ID都是Long类型,但是前端提交的是String类型,这时候就会报错:类型转换错误。
这个也是很坑的地方,需要这样操作:
@ApiOperation(value = "查询购物车列表")
@ApiImplicitParam(name="userId",value = "用户ID",required = true,paramType="path", dataType = "Long")
@GetMapping("/user/{userId}")
public QueryListResult<ShopCart> queryShopCartList(@PathVariable("userId") Long userId);
需要把:dataType设置成 Long,这样就会自动将String转换成Long。