对于一般的数据类型再用表单控制器的时候都可以自动绑定,但是对于时间的数据类型需要自己编写绑定器
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));
}
}
本文详细介绍了在表单控制器中自定义时间数据类型的绑定器,以实现自动绑定时间数据。通过注册定制编辑器,使得日期类型的数据能够通过用户友好的输入方式与表单对象成功关联。
3167

被折叠的 条评论
为什么被折叠?



