英文:
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 = "/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);
答案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 = "/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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论