SpringBoot方法具有过多的请求体参数。

huangapple go评论69阅读模式
英文:

SpringBoot Method has too many Body parameters

问题

我为调用我的RestApi创建了Feign客户端。当我尝试运行我的服务时,我从这个请求方法收到错误消息 "方法具有太多的Body参数"。对于 @RequestBody,我只使用了Object类型,因为每次我可以发送不同的请求体。

@RequestMapping(path = "/v1/products/{product}/companies/{companyId}", method = RequestMethod.POST,
            consumes = "application/json", produces = "application/json")
ResponseEntity<Object> createProduct(URI baseUri,
                                         @HeaderParam("tenant-id") String tenantId,
                                         @PathVariable("product") String product,
                                         @PathVariable("companyId") String companyId,
                                         @RequestBody Object reqBody);
英文:

I created feign client for call my RestApi. When I try to run my service I receive error from this requestMethod Method has too many Body parameters For @RequestBody I used just Object type, becaues each time I can send another body request.

@RequestMapping(path = &quot;/v1/products/{product}/companies/{companyId}&quot;, method = RequestMethod.POST,
            consumes = &quot;application/json&quot;, produces = &quot;application/json&quot;)
    ResponseEntity&lt;Object&gt; createProduct(URI baseUri,
                                         @HeaderParam(&quot;tenant-id&quot;) String tenantId,
                                         @PathVariable(&quot;product&quot;) String product,
                                         @PathVariable(&quot;companyId&quot;) String companyId,
                                         @RequestBody Object reqBody);

答案1

得分: 0

无法将Object用作类型,请尝试使用我们的Class来指定。框架无法确定要用哪个实体作为响应。

@RequestMapping(path = "/v1/products/{product}/companies/{companyId}", method = RequestMethod.POST,
                consumes = "application/json", produces = "application/json")
ResponseEntity<MyEntity> createProduct(URI baseUri,
                                             @HeaderParam("tenant-id") String tenantId,
                                             @PathVariable("product") String product,
                                             @PathVariable("companyId") String companyId,
                                             @RequestBody Object reqBody);
英文:

You can't use Object as the type, Please try to specify with our Class.The framework can't known which entity to use as response.

@RequestMapping(path = &quot;/v1/products/{product}/companies/{companyId}&quot;, method = RequestMethod.POST,
            consumes = &quot;application/json&quot;, produces = &quot;application/json&quot;)
    ResponseEntity&lt;MyEntity&gt; createProduct(URI baseUri,
                                         @HeaderParam(&quot;tenant-id&quot;) String tenantId,
                                         @PathVariable(&quot;product&quot;) String product,
                                         @PathVariable(&quot;companyId&quot;) String companyId,
                                         @RequestBody Object reqBody);

huangapple
  • 本文由 发表于 2020年8月10日 17:56:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63337985.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定