springMVC数据绑定

今天在是使用springMVC框架做一个添加操作,在前台日期对象选择的是带时分秒的,但传递到Control里时分秒就没了,Debug一下,发现方法签名中对象里的参数日期字段时分秒全是0.0.0,觉得很不解,就上网搜了一下,原来springMVC定义了很多编辑器,专门用属性的绑定,只需在Control加上一段

@InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new CustomDateEditor(
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));

    }

OK,问题解决。

猜你喜欢

转载自goodluck-wgw.iteye.com/blog/1695502