版权声明:本文为博主原创文章,未经博主允许也能转载,标明出处更好。 https://blog.csdn.net/fanpeizhong/article/details/88666396
Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dateExpire';
nested exception is org.springframework.core.convert.ConversionFailedException:
Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2029-03-12'; nested exception is java.lang.IllegalArgumentException]
在Controller里添加InitBinder即可:
@InitBinder
protected void init(HttpServletRequest request, ServletRequestDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}