search

Home  >  Q&A  >  body text

java - springmvc数据绑定如何指定构造函数

如果model里面自定义了多个构造函数(没有手写默认构造函数)
springmvc 如何进行数据绑定?

PHPzPHPz2890 days ago324

reply all(4)I'll reply

  • PHPz

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:53:23

    I don’t know what you are talking about...

    reply
    0
  • 迷茫

    迷茫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.

    reply
    0
  • 阿神

    阿神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中大部分项目都采用设值注入的,支持构造器注入

    In addition, most projects in Java use set value injection, and those that support constructor injection will generally leave APIs and interfaces for you. 🎜

    reply
    0
  • Cancelreply