我在这里读到:
正如我在this one等其他问题中看到的那样,我正在我的控制器中注册一个StringTrimmerEditor:
@Controller
public class MyController{
@InitBinder
public void initBinder(WebDataBinder binder)
{
binder.registerCustomEditor(StringTrimmerEditor.class,new StringTrimmerEditor(false));
}
它编译并运行,但不起作用,它不会修剪数据。我不知道我错过了什么。任何人?
感谢
答案 0 :(得分:6)
javadoc救援:
public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor)
Description copied from interface: PropertyEditorRegistry Register the given custom property editor for all properties of the given type. Specified by: registerCustomEditor in interface PropertyEditorRegistry Parameters: requiredType - the type of the property propertyEditor - the editor to register
该类不应该是编辑器的类。它应该是您希望编辑器应用的字段的类型:String.class