使用Spring 3.1并给定以下内容:
class Thing {
public Thing() {}
public Thing(String someProperty) {}
}
class ThingEditor extends PropertyEditorSupport{
@Override
public void setAsText(String text) {
if (text != null) {
Thing thing = new Thing(text); // or by using a setter method
setValue(thing);
}
}
}
class SomeController {
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Thing.class, new ThingEditor());
}
}
我发现只有在删除Thing
中带有字符串参数的构造函数时,才会调用已注册的属性编辑器 - 这样做是正确的吗?
为什么会这样做并忽略已注册的编辑器,如何让它停止这样做?
String
参数的构造函数。 - Koraktor