SpringMVC中不能自动将Spring转换成Date,所以要在Action实现类中添加日期转换器,用来转换日期格式,不然,jsp页面数据传输时会不能和javaBean实体类的属性相对应。在Action实现类中的构造方法后面添加initBinder方法
/**
* springMVC不能自动将String类型转换为Date类型
* 自定义类型转换器,将String-》Date类型(格式yyyy-MM-dd)
*/
@Override
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
//向springMVC内部注入一个自定义的类型转换器
//参数一:将String转成什么类型的字节码
//参数二:自定义转换规则
//true表示可以为空
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}