I'm beginning to understand a little bit of what happens on the background when a user requests some URL in the context of a Spring MVC Web Application. But I can't figure out when and how takes place the data binding, i.e. the mapping between the fields of an input form to a model object and the later injection of that object in the related handler method.
Anybody knows which classes and methods are implied, and where does this appear in the documentation?
If, for example, you're posting data which represents SomeBean
to this handler: public void (SomeBean someBean)
the following happens in Spring 4.
A InvocableHandlerMethod
will iterate over the method's parameters and will ask a HandlerMethodArgumentResolverComposite
instance to resolve the value for each parameter.
The HandlerMethodArgumentResolverComposite
will ask it's HandlerMethodArgumentResolver
s if they support the given parameter. If one supports the parameter this one is used for resolving the value.
A ModelAttributeMethodProcessor
will support the given parameter (SomeBean
) and will try to resolve it's value.
Inside it's resolveArgument
method the ModelAttributeMethodProcessor
will instantiate a target object of parameter's type.
It then will call a WebDataBinderFactory
to create a WebDataBinder
which is responsible for binding the request to the target object.
Once binded, the target will be returned and provided as an argument for the handler method.
P.s. Instead of the documentation you should read the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With