1. 程式人生 > >[Spring MVC] 表單提交日期轉換問題,比如可能導致封裝實體類時400錯誤

[Spring MVC] 表單提交日期轉換問題,比如可能導致封裝實體類時400錯誤

new tac med tab mat -m bin Edito ack

  三種格式的InitBinder

@InitBinder//https://stackoverflow.com/questions/20616319/the-request-sent-by-the-client-was-syntactically-incorrect-spring-mvc-jdbc-te
public void initBinder(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
@InitBinder// 弟弟通過qq發送的
public void initBinder(ServletRequestDataBinder binder){
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),
true));
}
@InitBinder//露露通過飛秋發送的
public void initBinder(ServletRequestDataBinder binder) {
binder.registerCustomEditor(Date.class, new CustomDateEditor(
new SimpleDateFormat("yyyy-MM-dd"), true));
}

[Spring MVC] 表單提交日期轉換問題,比如可能導致封裝實體類時400錯誤