How does Spring data binding work in the background?

I'm starting to understand a bit of what happens in the background when a user requests a URL in the context of a Spring MVC web application. But I cannot understand when and how data binding occurs, i.e. The mapping between the input form fields and the model object and the subsequent injection of this object in the associated handler method.

Does anyone know which classes and methods are implied, and where does this appear in the documentation?

+7
java spring spring-mvc data-binding
source share
1 answer

If, for example, you send data that represents SomeBean this handler: public void (SomeBean someBean) in Spring 4, the following happens.

  • A InvocableHandlerMethod will InvocableHandlerMethod over the method parameters and ask the HandlerMethodArgumentResolverComposite instance to resolve the value for each parameter.

  • HandlerMethodArgumentResolverComposite will request HandlerMethodArgumentResolver if they support this parameter. If one supports a parameter, this one is used to resolve the value.

  • A ModelAttributeMethodProcessor will support this parameter ( SomeBean ) and will try to solve it.

  • Inside the resolveArgument method resolveArgument ModelAttributeMethodProcessor will instantiate the target of the parameter type.

  • He then calls WebDataBinderFactory to create a WebDataBinder that is responsible for binding the request to the target.

  • After binding, the target will be returned and provided as an argument to the handler method.

Ps Instead of documentation, you should read the source code.

+13
source share

All Articles