Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Spring MVC using setter methods to set the properties of ModelAttribute objects?

Is Spring MVC using getters and setters to set the values of ModelAttribute objects? Can you please cite me sources that says so. And if not, how could we force Spring MVC to use setters to set the properties of the model object?

Thanks.

like image 435
supertonsky Avatar asked Oct 09 '22 20:10

supertonsky


1 Answers

I don't know if this really answers the question, but I found this quote in the documentation:

Command or form objects to bind request parameters to bean properties (via setters) or directly to fields, with customizable type conversion, depending on @InitBinder methods and/or the HandlerAdapter configuration. ... The ModelAttribute annotation can be used on a method argument to customize the model attribute name used.

This seems to imply that setters will be used if available, with direct update of the fields as a fallback.

But if you want a definitive answer, look at the source code.

like image 118
Stephen C Avatar answered Oct 13 '22 12:10

Stephen C