Spring common interfaces and classes (iii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.