如果model里面自定义了多个构造函数(没有手写默认构造函数)
springmvc 如何进行数据绑定?
PHPz2017-04-17 17:53:23
I guess Spring here should also get the instance through reflection and then set the value.
If there is no parameterless constructor, there should be an exception when calling newInstance()
during reflection.
Please give me some advice from the experts downstairs.
迷茫2017-04-17 17:53:23
If a Spring bean does not have a default constructor, you need to clearly specify which constructor to use and what parameter values to pass in the configuration.
阿神2017-04-17 17:53:23
Spring should be constructed by calling the parameterless constructor, and then use setto set the value and inject
. So if you don't set it, you should get an error.
It seems that it is not possible to specify a constructor... I am not sure. You can check Spring's API. 设值注入
的。所以你不设定应该会报错的。
指定构造器这个事情好像办不到吧...我不太确定,你可以查查Spring的api。
另外 java中大部分项目都采用设值注入
的,支持构造器注入
set value injection
, and those that support constructor injection
will generally leave APIs and interfaces for you. 🎜