About the resolution of the SPRINGMVC date problem in addition to this blog, "SPRINGMVC date format data transfer resolution @DateTimeFormat use and Configuration" article,
There are also the following ways:
Add this code to the controller:
1 @InitBinder2 Public voidInitbinder (Servletrequestdatabinder binder) {3 /**4 * field format for automatic conversion of date types5 */6SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd");7Binder.registercustomeditor (Date.class,NewCustomdateeditor (SDF,true));8 9 Ten}
Note that if the foreground has multiple date formats, There are no eggs to write in a manner similar to the following:
1 @InitBinder2 Public voidInitbinder (Servletrequestdatabinder binder) {3 /**4 * field format for automatic conversion of date types5 */6SimpleDateFormat SDF1 =NewSimpleDateFormat ("Yyyy-mm-dd");7SimpleDateFormat SDF2 =NewSimpleDateFormat ("yyyy mm month");8 Try {9Binder.registercustomeditor (Date.class,NewCustomdateeditor (SDF2,true));Ten}Catch(Exception e) { OneBinder.registercustomeditor (Date.class,NewCustomdateeditor (SDF1,true)); A } - -}
How to solve it?
Refer to this question: http://bbs.csdn.net/topics/380055180
The original content is as follows :
----------------------------------------------------------Dividing line begins-----------------------------------------------------------
Configuration file is
12345 |
<
bean
class
=
"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
>
<
property
name
=
"webBindingInitializer"
>
<
bean
class
=
"xx.xxx.MyBindingInitializer"
/>
</
property
>
</
bean
>
|
In the Mybindinginitializer, the Initbinder method
Binder.registercustomeditor (Date.class, New Xxxeditor ());
In Xxxeditor's Setastext method, the system uses all possible format formats one by one to try, catch exceptions, and finally bind correctly.
-------------------------------------------------------end of the dividing line------------------------------------------------------------- ---
As for the Xxxeditor how to write, we can refer to the example of Customdateeditor, That is: Org.springframework.beans.propertyeditors.CustomDateEditor source code in how to write.
SPRINGMVC Date format pass-through method of two (total two) @InitBinder use