springmvc使用spring自带日期类型验证

控制器

@Controller
public class MyController { // 处理器方法
@RequestMapping(value = "/first.do")
public String doFirst(Date birthday, int age) {
return "/jsp/two.jsp";
} // 自定义一个方法
@InitBinder
public void initBinder(WebDataBinder binder) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//0需要返回的类型,1传入一个带格式的df,2允许为空
binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
}
}
上一篇:TravelCMS旅游网站系统前台诞生记-2(后台框架篇)


下一篇:关于js中两种定时器的设置及清除(转载)