spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'的解决方法

在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错:

Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'expert.birthdate'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'birthdate': no matching editors or conversion strategy found
在对应的Controller控制器中添加

 @InitBinder
    protected void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

你可能感兴趣的:(spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'的解决方法)