版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
方法一
在当前方法所在的类中添加方法
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));
}
方法二
在实体类的Date类型的属性上添加注解
@DateTimeFormat(pattern = "yyyy-MM-dd")