Imagine a code like this one:
@RequestMapping(value=\"/users\", method=RequestMethod.GET)
public String list(Model model) {
...
}
@InitBinder(\"user\")
That's not really what @ModelAttribute
is for. If you use it as a method parameter, it puts the annotated parameter into the model (that's fine). If you put it on a method, it's called every time to provide reference data that every method in the controller should have access to.
If you want to take control of building up your User object, you have several options. The two that are most obvious to me are: