Swagger Long类型转换错误的问题

我们设计接口的时候,往往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。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章