首先我们看看我的SpringBoot接口
@ApiOperation("商品详情")
@ApiResponses(@ApiResponse(code = 200, message = "ok", response = GoodsDetailsVo.class))
@GetMapping("detail")
@ApiImplicitParams({
@ApiImplicitParam(value = "用户id", name = "userId"),
@ApiImplicitParam(value = "商品id", name = "id"),
})
public Object detail(@LoginUser Integer userId,
@NotNull Integer id) {
// 商品信息
LitemallGoods info = goodsService.findById(id);
// 商品属性
Callable<List> goodsAttributeListCallable = () -> goodsAttributeService.queryByGid(id);
// 商品规格 返回的是定制的GoodsSpecificationVo
Callable<Object> objectCallable = () -> goodsSpecificationService.getSpecificationVoList(id);
然后我们看看Swagger接口
百度了之后,都建议改get请求为post,这不能解决实质问题呀,我不可能所有请求都用post呀。
后来我发现是自己的参数设置请求类型确实有问题,paramType默认是body传入,所有我只需要修改为下面这样
@ApiOperation("商品详情")
@ApiResponses(@ApiResponse(code = 200, message = "ok", response = GoodsDetailsVo.class))
@GetMapping("detail")
@ApiImplicitParams({
@ApiImplicitParam(value = "用户id", name = "userId", paramType = "query"),
@ApiImplicitParam(value = "商品id", name = "id", paramType = "query"),
})
public Object detail(@LoginUser Integer userId,
@NotNull Integer id) {
// 商品信息
LitemallGoods info = goodsService.findById(id);
// 商品属性
Callable<List> goodsAttributeListCallable = () -> goodsAttributeService.queryByGid(id);
修改后的swagger接口