0

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 1

0

Feel free to use ModelAttribute as the values will be populated by default values like 0 for integer, More info can be found here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for reply..but if it is optional then how can I make some fields required
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); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.