springmvc 時間類型參數接收

{"success":false,"msg":"org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors\nField error in object 'vip' on field 'vip_regtime': rejected value [2014-10-11]; codes [typeMismatch.vip.vip_regtime,typeMismatch.vip_regtime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [vip.vip_regtime,vip_regtime]; arguments []; default message [vip_regtime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'vip_regtime'; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: \"2014-10-11\"]"}java

以上異常內容spring

/**
     * 時間轉換器
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
        fmt.setLenient(false);
        CustomDateEditor dateEditor = new CustomDateEditor(fmt, true);
        binder.registerCustomEditor(Date.class, dateEditor);
    }
相關文章
相關標籤/搜索