TypeError: Failed to execute ‘fetch‘ on ‘Window‘: Request with GET/HEAD method cannot have body.

加上了@ApiImplicitParam注解后,swagger出现的报错信息

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("分页查询品牌列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageNum",value="当前页No.",required=true,paramType="form"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="form")
    })
    public CommonResult<CommonPage<PmsBrand>> listBrand(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        List<PmsBrand> brandList = demoService.listBrand(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(brandList));
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取指定id的品牌详情")
    @ApiImplicitParam(name="id",value="记录Id",required=true,paramType="form")
    public CommonResult<PmsBrand> brand(@PathVariable("id") Long id) {
        return CommonResult.success(demoService.getBrand(id));
    }

TypeError: Failed to execute ‘fetch’ on ‘Window’: Request with GET/HEAD method cannot have body.

在这里插入图片描述

尝试把swagger的参数注解删除,错误消失。

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("分页查询品牌列表")
    public CommonResult<CommonPage<PmsBrand>> listBrand(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        List<PmsBrand> brandList = demoService.listBrand(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(brandList));
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取指定id的品牌详情")
    public CommonResult<PmsBrand> brand(@PathVariable("id") Long id) {
        return CommonResult.success(demoService.getBrand(id));
    }

在这里插入图片描述

发现问题:swagger上显示的参数类型发生了变化

在这里插入图片描述

1.在加上注解的代码后显示的参数类型是formData
2.删除注解代码后显示的参数类型是path
所以去查了一下参数类型对应的内容:

 paramType:表示参数放在哪个地方
    header-->请求参数的获取:@RequestHeader(代码中接收注解)
    query-->请求参数的获取:@RequestParam(代码中接收注解)
    path(用于restful接口)-->请求参数的获取:@PathVariable(代码中接收注解)
    body-->请求参数的获取:@RequestBody(代码中接收注解)
    form(不常用)

修改注解代码的参数类型,问题解决。

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("分页查询品牌列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageNum",value="当前页No.",required=true,paramType="query"),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true,paramType="query")
    })
    public CommonResult<CommonPage<PmsBrand>> listBrand(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize) {
        List<PmsBrand> brandList = demoService.listBrand(pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(brandList));
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("获取指定id的品牌详情")
    @ApiImplicitParam(name="id",value="记录Id",required=true,paramType="path")
    public CommonResult<PmsBrand> brand(@PathVariable("id") Long id) {
        return CommonResult.success(demoService.getBrand(id));
    }

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值