Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'demoQo' on field 'endTime': rejected value [2021-10-31 23:59:59]; codes [typeMismatch.demoQo.endTime,typeMismatch.endTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [demoQo.endTime,endTime]; arguments []; default message [endTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2021-10-31 23:59:59'; nested exception is java.lang.IllegalArgumentException]
Field error in object 'demoQo' on field 'startTime': rejected value [2021-10-01 00:00:00]; codes [typeMismatch.demoQo.startTime,typeMismatch.startTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [demoQo.startTime,startTime]; arguments []; default message [startTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'startTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2021-10-01 00:00:00'; nested exception is java.lang.IllegalArgumentException]]
原因说明:
错误重点:
Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endTime';
意思是无法将string类型转换Date类型
解决:将传参中Date类型的startTime,endTime换成String类型
即:
private Date startTime;
private Date endTime;
换成:
private String startTime;
private String endTime;