//在controller内添加此方法,最好是放到BaseController中,其他类继承他就行
//这种方法的缺陷:一个比较大的项目的话,可能需要有带时间的日期,也有可能是不带日期的日期,这种办法只能兼用一种日期格式数据
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(
Date.class,
new CustomDateEditor(
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),
true //true:允许输入空值,false:不能为空值
)
);
}