2017-07-26 72 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