第一种方式:在接收参数的controller中加入:
@InitBinder
public void initBinder(WebDataBinder binder) {
//binder.setDisallowedFields("name");
CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true);
binder.registerCustomEditor(Date.class, editor);
}
第二种方式:注解方式 在实体类属性上加@DateTimeFormat(pattern="yyyy-MM-dd")
注解
原理及其他方式有待研究