How does Spring 2.5 map incoming request data to ModelAttribute command?

I have used Spring 2.0 and now I am using Spring 2.5. In fact, Spring 2.5 made life very easy in regards to web controllers. In my opinion, the issue is that in 2.0 we needed to set a command class and hence AbstractFormController was used to populate that command object for us. In Spring 2.5 we don't do it the way it comes, you know which class to use? It depends on the type of parameter we have annotated with @ModelAttribute ("command") on?

If yes, then please let me know any "Utils" class that provides an exact mechanism where I can pass the HttpRequest and the class name (or class object) and that will return the populated object to me!

Hope you have my question.

Thanks in advance.

0


source to share


1 answer


Web MVC annotation binding ultimately depends on

org.springframework.beans.AbstractPropertyAccessor

which has two concrete implementations:

org.springframework.beans.BeanWrapperImpl org.springframework.beans.DirectFieldAccessor



Both recognize a Java object that will be the target for setting properties.

First, BeanWrapperImpl uses setter / getter methods for java object and the other one directly. Both check that the methods / fields are public / accessible, and if otherwise, use the reflection setAccessible (true) to ensure that it is set.

An AbstractPropertyAccessor is instantiated from Web MVC, and the HttpRequest parameter map is passed to AbstractPropertyAccessor # setPropertyValues.

Once called, the java object is filled with whatever is in the map

+3


source







All Articles