对于一般的数据类型再用表单控制器的时候都可以自动绑定,但是对于时间的数据类型需要自己编写绑定器
public class EmpController extends AbstractCommandController{
@Override
protected ModelAndView handle(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, BindException arg3)
throws Exception {//arg2 为表单提交的数据封装成的对象
Emp emp = (Emp) arg2;
System.out.println(emp);
return null;
}
@Override
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}
}