First, Customeditorconfigurer class
Customeditorconfigurer can read the class that implements the Java.beans.PropertyEditor interface and convert the string to the specified type. It is more convenient to use PropertyEditorSupport. PropertyEditorSupport implements the PropertyEditor interface, the Setastext must be redefined.
Public classHello {PrivateString message; Privateuser User; PublicString getMessage () {returnmessage; } Public voidsetmessage (String message) { This. Message =message; } PublicUser GetUser () {returnuser; } Public voidsetUser (user user) { This. user =user; }}
The
custom Property editor inherits the PropertyEditorSupport class, overriding the Setastext method.
public class usereditor extends propertyeditorsupport{@Override public void setastext (String text) IllegalArgumentException { //
string[] arr = Text.split ("," ); Integer Age = new Integer (arr[1 = new user (); User.setname (arr[ 0
Bean configuration
<BeanID= "Configbean"class= "Org.springframework.beans.factory.config.CustomEditorConfigurer"> < Propertyname= "Customeditors"> <Map> <!--variables of type user are indirectly set by Usereditor - <entryKey= "User"> <BeanID= "Usereditor"class= "Usereditor"/> </entry> </Map> </ Property></Bean> <BeanID= "Hello"class= "Hello"> < Propertyname= "message"value= "Hello" /> < Propertyname= "User"value= "chenjumin,20"/><!--A variable of type user declares a custom property editor whose value is defined as a comma-delimited string - </Bean>
Spring common interfaces and classes (iii)