解决方案 »

  1.   

    我参考StackOverflow上的说法 
    给Controller添加了
        @InitBinder
        private void dateBinder(WebDataBinder binder) {
            //The date format to parse or output your dates
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            //Create a new CustomDateEditor
            CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
            //Register it as custom editor for the Date type
            binder.registerCustomEditor(Date.class, editor);
        }
    但是不起作用 貌似这个是把Date转换成String的,也不知道我理解的对不对。
    另外个人觉得写那种Convert<T,S>,似乎是可以的,但是非常繁琐,因为如果有好多各类都有date类型,每个类都要去写一遍,也是醉了?
    要么自己用反射去遍历javabean的成员,并且和HttpServletRequest的attribute去对照,然后发现Date类型就直接用格式去转换?只是觉得spring mvc应该提供了一个转换配置 的功能