我們設計接口的時候,往往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。