I have such method in spring controller
@RequestMapping(value = "/updateArticle", method = RequestMethod.POST)
@ResponseBody
public void updateArticle(Long id, String name, String description) {
...
}
I want the id, and name to be REQUIRED. In the other words, if they are null values, then an exception must be thrown.
How can I do that? Is there any annotation for this or something like that?
Thanks
Yes, there is. @RequestParam(required=true)
See the docs.
Required flag is even true by default, so all you need to do is:
@RequestMapping(value = "/updateArticle", method = RequestMethod.POST)
@ResponseBody
public void updateArticle(@RequestParam Long id, @RequestParam String name, @RequestParam String description) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With