I would like to pass many @RequestParam annotated parameters to a Model object in an easy fashion.
Currently, I see two alternatives:
- You can do it by hand (not so easy, example below)
- You can create command objects for related parameters, and pass the object to your model.
I'm looking for a third way, which will do this for me automatically.
@RequestMapping
public void handle(@RequestParam String p1, @RequestParam String p2,
@RequestParam String p3, @RequestParam String p4, Model model) {
model.addAttribute("p1",p1);
model.addAttribute("p2",p2);
model.addAttribute("p3",p3);
model.addAttribute("p4",p4);
}
The main reason I need this is to pass the parameters in a POST handler to flash attributes easily in case of an error.
Update: @ModelAttribute method (or specifying a bean without it, I think they're basically the same when you don't give @ModelAttribute a value) is actually the the second method I mentioned in the question. I'm looking for a way other than those I mentioned.