springMVC中Date类型入参

方法1  把前台传来的字符串在controller中转换  即入参设置成string类型  在controller方法中把string转换成date  这种方法使用少量的转换  不做过多的介绍

方法2    一)在类中定义方法

@InitBinder
    public void dateformart(HttpServletRequest request,ServletRequestDataBinder binder){
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"), true));
    }

这样就会在入参赋值的时候把string转换成date

注意 配置文件中配置下面这个标签

<mvc:annotation-driven />

 

posted @ 2018-03-30 21:39  菜鸟~风  阅读(625)  评论(0)    收藏  举报