【问题标题】:Spring StringTrimmerEditor not workingSpring StringTrimmerEditor 不工作
【发布时间】:2012-01-28 19:22:36
【问题描述】:

正如我在这里读到的:

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));
     }

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

谢谢

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    javadoc 救援:

    public void registerCustomEditor(Class requiredType, 属性编辑器属性编辑器)

    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

    【讨论】:

    • 我不得不承认我昨天晚上很晚很懒,所以我没有研究,而是在这里问,期待今天早上有答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多