Reputation: 21
few days ago I passed SpringMVC level evaluation test on my company, and I found that I don't have enough knowledge to answer one question. But I'm wondering what is the correct answer??? So it will be awesome if You help me!
You have the following PersonController class and correctly defined web.xml and Spring context
The following request has been submitted using POST method: http://xxxx/person/add?name=John
Please, fill the placeholders so that submitted request would result into person object being saved successfully and method addPerson would be called only in case request doesn't contain "id" parameter. Values in placeholders should not contain spaces.
Upvotes: 2
Views: 16175
Reputation: 12378
PLACEHOLDER1 :
@Controller
@RequestMapping("person")
PLACEHOLDER2 :
@RequestMapping(value = "add", method = RequestMethod.POST)
And you can read document from Spring official site.
Edited:
About id
, if you request url is like http://xxxx/person/add/12345?name=John, then you can do it like this:
@RequestMapping(value = "add/{id}", method = RequestMethod.POST)
public String addPerson(@RequestParam("name") String name, @PathVariable("id") String id)
here you can get 12345 as id
.
Upvotes: 7