Spring MVC 是否使用 getter 和 setter 来设置 ModelAttribute 对象的值?你能引用我这样说的消息来源吗?如果不是,我们如何强制 Spring MVC 使用 setter 来设置模型对象的属性?
谢谢。
最佳答案
我不知道这是否真的回答了问题,但我在文档中找到了这句话:
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.
这似乎意味着如果可用,将使用 setter,直接更新字段作为后备。
但如果你想要一个明确的答案,请查看源代码。
关于java - Spring MVC 是否使用 setter 方法来设置 ModelAttribute 对象的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9106524/