How does Spring MVC support data binding?

Data binding in Spring MVC is the process of automatically converting incoming HTTP request data — form fields, query parameters, path variables — into strongly typed Java objects that controller methods can work with directly.

Key Points: • @ModelAttribute binds a full set of request parameters onto the properties of a Java object using matching setter names. • @RequestParam binds a single named parameter to a method argument, with support for defaults and optionality. • BindingResult captures any conversion or validation failures so they can be handled gracefully instead of throwing an exception. • PropertyEditors and, more commonly today, Converter/Formatter implementations registered via @InitBinder or a global ConversionService handle non-trivial type conversions like dates. • Binding works for both simple types and nested object graphs, matching request parameter names to nested property paths.

Example: A search form with fields for keyword, minPrice, and maxPrice can bind directly onto a SearchCriteria object via @ModelAttribute, so the controller method receives a single populated object instead of manually parsing each request parameter.

Interview Tip: A concise interview answer is:

"Spring MVC binds request data to Java objects using @ModelAttribute for full objects and @RequestParam for individual values, converting strings to the right types automatically and via custom converters or formatters when needed. BindingResult lets me capture and respond to any binding or validation errors instead of the request failing outright."