Controller method with two @RequestBody

See original GitHub issue

I extend spring-mvc’s HandlerMethodArgumentResolver to support multi @ReqestBody param on controller’s method. The @ReqestBody annotation was rewrite to support value param:

@RequestMapping(method=RequestMethod.POST, value="person-cars-post")
@ApiOperation(value = "create person and car", httpMethod="POST")
public ModelAndView<Person> createPersonAndCar1(@RequestBody("person") Person person, @RequestBody("car") Car car) {
    return ModelAndViewUtils.successWithView(person, "persons/list");
}

The program works fine, but springfox parses the two params to two body. On site of the swagger ui shows:

Parameters


person:

 {
  "addresses": [
    {
      "id": "string",
      "name": "string"
    }
  ],
  "id": "string",
  "name": "string",
  "sex": "string"
}

car :

{
  "color": "string",
  "id": "string",
  "level": "string"
}

When I clicked “Try it out!”, it only sended the person’s input.

Shoud i modify the swagger ui or config springfox?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mnpraveensinghcommented, Jun 26, 2018

if you will use like these you will get desired output. Here ( @RequestPart String data ) is a model class you can not pass model class directly as parameter, so you need to give datatype & after that you should convert it. @RequestMapping(value = “/mail”, consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }, method = RequestMethod.POST) public ResponseEntity<String> uploadFile(@RequestPart String data, @RequestPart MultipartFile file)

0reactions
cwocwocommented, Jun 13, 2015

Thanks! I will try to modify the swagger ui.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing multiple variables in @RequestBody to a Spring MVC ...
You can do it like this way: @RequestMapping(value = "/Test", method = RequestMethod. POST) @ResponseBody public boolean getTest(@RequestBody ObjectNode ...
Read more >
Spring-mvc – Multiple @RequestBody values in one controller ...
I'm receiving error 400 when I send PATCH request to my endpoint that looks like this @RequestMapping(value = "...", method = RequestMethod.
Read more >
Passing multiple variables in @RequestBody to a Spring MVC ...
Coding example for the question Passing multiple variables in @RequestBody to a Spring MVC controller using Ajax-Spring MVC.
Read more >
Support multiple @RequestBody [SPR-9434] #14070 - GitHub
There is a very good chance you will need this functionality in more than one controller method.
Read more >
Spring @RequestBody - binding method ... - ZetCode
@RequestBody annotation binds request body to method parameters. The process of serialization/deserialization is performed by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found