I am working on spring mvc and I want to make some parameters in modelattribute as optional. Ex. We can use @RequestMapping to set optional parameters by required=false. So I need something like this in @modelattribute. I don't want to use RequestParam because I have big list of parameters. Is there any other way ?
1 Answer
Feel free to use ModelAttribute as the values will be populated by default values like 0 for integer, More info can be found here
2 Comments
Guest
Thanks for reply..but if it is optional then how can I make some fields required
Eshan I.
Try using
@Valid with your model attribute. specify code here please in your OP. If you could do something like @ModelAttribute("querier") public void populateIds (@RequestParam(value = "querier", required = false) String querier, Model model) { model.addAttribute("querier", querier == null ? "quest" : querier); }