@ModelAttribute serves two related purposes in Spring MVC: binding submitted form data onto a Java object as a method parameter, and adding data to the model so it's available to a view or across multiple handler methods.
An edit-profile form uses @ModelAttribute to both load the current user's data into the form on GET and bind the submitted changes back onto a User object on POST, keeping the binding logic consistent in both directions.
@ModelAttribute("user")
public User populateUser(@RequestParam Long id) {
return userService.findById(id);
}A concise interview answer is
@ModelAttribute binds request data onto a Java object for form submissions, and when used on its own method it adds shared data to the model for every request handled by that controller. It's what makes pre-populating an edit form and processing its submission use the same binding mechanism.
Last updated: 16 July 2026
Previous question: How can you handle form submission in Spring MVC?
Next question: Can you describe form validation in Spring MVC?