Spring StringTrimmerEditor无法正常工作

时间:2011-12-27 22:14:05

标签: java spring spring-mvc

我在这里读到:

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/portlet.html#portlet-ann-webdatabinder

正如我在this one等其他问题中看到的那样,我正在我的控制器中注册一个StringTrimmerEditor:

@Controller
public class MyController{


    @InitBinder
     public void initBinder(WebDataBinder binder) 
     {
       binder.registerCustomEditor(StringTrimmerEditor.class,new  StringTrimmerEditor(false));
     }

它编译并运行,但不起作用,它不会修剪数据。我不知道我错过了什么。任何人?

感谢

1 个答案:

答案 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