在spring的mvc中form中的属性不能是java.util.Date的类型!在struts中的form中可以,但是在spring中老是报数据绑定错误,要是把这个date类型的字段变成String类型就可以了!不知道能不能用date类型的!!!!求救。

解决方案 »

  1.   

    protected void initBinder(HttpServletRequest request, 
        ServletRequestDataBinder binder) throws Exception { 
        DateFormat fmt = new SimpleDateFormat("yyyy-M-d"); 
        CustomDateEditor dateEditor = new CustomDateEditor(fmt, true); 
        binder.registerCustomEditor(Date.class, dateEditor); 
        super.initBinder(request, binder); 
      

  2.   

    那我请问您一下,您的这个方法写在form中还是写在什么地方呢?
      

  3.   

    用了这个方法后就可以再控制层中用beanutils.copyProperties();这个方法了是吗?CustomDateEditor 这个类是不是form类呀!