Try to search your question here, if you can't find : Ask Any Question Now ?

Passing multiple variables in @RequestBody to a Spring MVC controller using Ajax

HomeCategory: stackoverflowPassing multiple variables in @RequestBody to a Spring MVC controller using Ajax
john asked 2 weeks ago

Is it necessary to wrap in a backing object? I want to do this:

@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody String str1, @RequestBody String str2) {}

And use a JSON like this:

{
    "str1": "test one",
    "str2": "two test"
}

But instead I have to use:

@RequestMapping(value = "/Test", method = RequestMethod.POST)
@ResponseBody
public boolean getTest(@RequestBody Holder holder) {}

And then use this JSON:

{
    "holder": {
        "str1": "test one",
        "str2": "two test"
    }
}

Is that correct? My other option would be to change the RequestMethod to GET and use @RequestParam in query string or use @PathVariable with either RequestMethod.

1 Answers
Best Answer
Mikhail answered 2 weeks ago
Your Answer

2 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com