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));
    }
}
原文地址:https://www.cnblogs.com/cnsdhzzl/p/6097922.html