springmvc现有日期格式转换会丢失掉时分秒,我们只需在Controller中重写initBinder 方法就可以,代码如下:
@Override
public void initBinder(WebDataBinder binder) {
super.initBinder(binder);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
CustomDateEditor dateEditor = new CustomDateEditor(df, true);
//表示如果命令对象有Date类型的属性,将使用该属性编辑器进行类型转换
binder.registerCustomEditor(Date.class, dateEditor);
}