Initialize parameter bindings: Date format
A: First we do a date format binding, configuration initialization parameter binding and custom type conversion have the same wonderful
The configuration steps are as follows:
1. We first configure the Applicationcontext.xml for scanner configuration
2. Next we define its processor, and the binding of the method (@InitBinder)
3. Test in a single date format:
<form action= "${pagecontext.request.contextpath}/first.do" method= "POST" > Two: multiple date formats
1. First we need to inherit an editor (Propertieseditor)
Rewrite it's Setastext method
So that subsequent assignments to the Date object
public class Mydateeditor extends propertieseditor{ @Override public void Setastext (String source) throws illegalargumentexception { SimpleDateFormat sdf=getdate (source); try {setValue (Sdf.parseobject (source)), } catch (ParseException e) {e.printstacktrace (); } } Private SimpleDateFormat getDate (String source) {SimpleDateFormat sdf=null;if (pattern.matches ("^\\d{4}-\\d{2}-\\d{2 }$ ", source)) {sdf=new SimpleDateFormat (" Yyyy-mm-dd ");} else if (pattern.matches ("^\\d{4}/\\d{2}/\\d{2}$", source)) {sdf=new SimpleDateFormat ("Yyyy/mm/dd");} else if (pattern.matches ("^\\d{4}\\d{2}\\d{2}$", source)) {sdf=new SimpleDateFormat ("YyyyMMdd");} else {throw new Typemismatchexception ("", Date.class);} return SDF;}}
2. Configuring the Processor
3. Perform a variety of date format tests:
Now belongs to your own not always belong to you, initialization parameters will also change with the binding.
----warned yourself
Initialization parameter bindings for SPRINGMVC