Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring REST multiple @RequestBody parameters, possible?

People also ask

How do I pass multiple parameters in spring REST URL?

@RequestMapping(value="mno/{objectKey}", method = RequestMethod. GET, consumes="application/json") public List<Book> getBook4(@RequestParam ObjectKey objectKey) { ... } @RequestMapping(value="ghi/{objectKey}",method = RequestMethod. GET) public List<Book> getBook2(@PathVariable ObjectKey objectKey) { ... }

Is @RequestBody required with @RestController?

If you don't add @RequestBody it will insert null values (should use), no need to use @ResponseBody since it's part of @RestController.

How does RequestBody work in spring?

Simply put, the @RequestBody annotation maps the HttpRequest body to a transfer or domain object, enabling automatic deserialization of the inbound HttpRequest body onto a Java object. Spring automatically deserializes the JSON into a Java type, assuming an appropriate one is specified.


I'm pretty sure that won't work. There may be a workaround, but the much easier way would be to introduce a wrapper Object and change your signature:

public class PersonContext{
    private UserContext userContext;
    private Person person;
    // getters and setters
}


public Person createPerson(@RequestBody PersonContext personContext)