In spring MVC, the binding page passes the time string data to the date type with an error:
Failed to convert property value of type [java.lang.String] to required type [Java.util.Date] for property ' Expert.birthda Te '; Nested exception is Java.lang.IllegalArgumentException:Cannot convert value of type [java.lang.String] to required type [ Java.util.Date] for property ' birthdate ': no matching editors or conversion strategy found
Workaround One:
1. Enable the corresponding controller controllers to inherit extends Simpleformcontroller
2. Overriding the Initbinder method
protected void Initbinder (httpservletrequest request, Servletrequestdatabinder Binder){ new SimpleDateFormat ("Yyyy/mm/dd"); Dateformat.setlenient (false); Binder.registercustomeditor (Date. class New false)); }
Note the SimpleDateFormat date format is consistent with the page date format!
Workaround Two:
Spring3.0 above Simpleformcontroller is obsolete, the latest way is to use @initbinder annotations
In the corresponding controller controllers
@InitBinder protectedvoid init (httpservletrequest request, Servletrequestdatabinder binder) { new SimpleDateFormat ("Yyyy-mm-dd"); Dateformat.setlenient (false); Binder.registercustomeditor (Date. class New false )); }
Spring MVC appears Failed to convert property value of type ' java.lang.String ' to required type ' java.util.Date ' for property ' E Ndtime '