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));
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM