微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swagger MethodArgumentTypeMismatchException:无法将参数转换为类型

如何解决Swagger MethodArgumentTypeMismatchException:无法将参数转换为类型

昂首阔步有奇怪的行为。我正在使用3.0.0版。

我的记录器中的错误MethodArgumentTypeMismatchException: The parameter 'configId' of value '{configId}' Could not be converted to type 'Long'

昂首阔步的错误显示

{
  "status": "BAD_REQUEST","timestamp": "07-10-2020 04:23:55","message": "The parameter 'configId' of value '{configId}' Could not be converted to type 'Long'","debugMessage": "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: \"{configId}\"","subErrors": null
}

怎么可能是\"{configId}\"?我在做什么错了?

我的方法如下:

  @ApiOperation(
      value = "Deletes a configuration of a custom MLP in the database",notes = "This can only be done by the owner of the config.",response = ResponseEntity.class,authorizations = @Authorization(value = "Bearer"))
  @ApiResponses(
      value = {
        @ApiResponse(code = 200,message = "Successfully deleted custom MLP configuration"),@ApiResponse(code = 401,message = "You are not authorized to delete the resource"),@ApiResponse(
            code = 403,message = "Accessing the resource you were trying to reach is forbidden"),@ApiResponse(code = 404,message = "The resource you were trying to reach is not found")
      })
  @PreAuthorize("@mlpConfigServiceImpl.ownedByUser(#mlpConfigId,authentication.name)")
  @DeleteMapping(value = "/delete/{configId}")
  public ResponseEntity<Object> deleteMlpConfig(
      @ApiParam(
              name = "MlpConfig Id",value = "Id of a custom MLP configuration",type = "long",format = "long",example = "1")
          @PathVariable("configId")
          @NotNull
          Long mlpConfigId,Authentication authentication) {
    mlpConfigService.deleteById(mlpConfigId);
    return ResponseEntity.ok(new MessageResponse("Configuration removed successfully!"));
  }

唯一有趣的路径是:

 @ApiParam(
           name = "MlpConfig Id",example = "1")
      @PathVariable("configId")
      @NotNull
      Long mlpConfigId,

我的依赖关系:

compile group: 'io.springfox',name: 'springfox-swagger2',version: '3.0.0'
compile group: 'io.springfox',name: 'springfox-swagger-ui',name: 'springfox-boot-starter',name: 'springfox-data-rest',name: 'springfox-bean-validators',version: '3.0.0'

我唯一想做的就是给1作为示例ID并能够执行它。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。