springMVC,前端日期格式的文本传递给java中的Date对象

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_38861828/article/details/100632155

方法一

在当前方法所在的类中添加方法

@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")

猜你喜欢

转载自blog.csdn.net/qq_38861828/article/details/100632155