2017-07-26 56 views
0

我尝试Spring MVC的日期格式化器使用的粘合剂这样Spring MVC的错误日期格式

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

但我需要格式化"dd-MM-YYYY"。如果我用这个格式保存的MySQL错误的日期

表单数据:07-12-1980
MySQL数据:0013-05-02

回答

0

在你的POJO尝试添加该到你的约会对象。

@DateTimeFormat(pattern = "dd/MM/yyyy") 
private Date dob; 

来源:here