I bumped into an answer about the usage of @ModelAttribute
on spring MVC here on stackoverflow, and learned that it was not actually required to be added into the method's parameter.
I looked for some controllers from our old project, deleted the annotation, and surprisingly the application still runs flawlessly without the @ModelAttribute
. Please see example below:
@RequestMapping(method = RequestMethod.POST, value = "/audit/filter")
public String getAuditLogsWithFilter(Model model, AuditLogFilter auditLogFilter, BindingResult bindingResult)
I have read some articles about it but I can not grasp onto why @ModelAttribute
is used for some method parameters particularly for spring controllers.
Can anybody provide a simple explanation into why that is? Or can someone enumerate some cases into which I should add the @ModelAttribute
annotation to my parameter object?