Beanwrapper is an excuse under the Org.springframework.beans package, the corresponding implementation class is Beanwrapperimpl, provides the corresponding Get/set method, and sets the readability and the writable property.
public class Company {private String Name private Employee managingdirector; public String getName () {return this.na Me } public void setName (String name) { THIS.name = name; } public Employee getmanagingdirector () {return this.managingdirector; } public void setmanagingdirector (Employee managingdirector) { Span class= "Hl-keyword" >this.managingdirector = Managingdirector; }}
Public class Employee { private String name; private float salary; Public String GetName () { return this.name;} public void SetName (String name) { this.name = name;} Public Float getsalary () { return salary;} public void Setsalary (float salary) { this.salary = salary;}}
Beanwrapper Company =New Beanwrapperimpl (New company ());Setting the company Name..company.setpropertyvalue ("Name","Some Company Inc.");... can also be do like this:propertyvalue value =New PropertyValue ("Name","Some Company Inc."); Company.setpropertyvalue (value);OK, let's create the director and tie it to the company:beanwrapper Jim =New Beanwrapperimpl (New Employee ()); Jim.setpropertyvalue ("Name","Jim Stravinsky"); Company.setpropertyvalue ( "Managingdirector", Jim.getwrappedinstance ()); //retrieving the salary of the managingdirector through the companyfloat salary = (Float) compan Y.getpropertyvalue ( "managingdirector.salary");
From the above code, Beanwrapper can be seen as the parent type after POJOs is transformed into a bean.
Spring introduces the concept of PropertyEditor, primarily for the purpose of implementing string types and other types of conversions. The most common is the conversion of string types and date types, and Customdateeditor is a specialized property editor for Java.util.Data
that supports commonly used dataformat. In the actual operation often encountered in the form of date strings and JavaBean in the date type of the properties of the automatic conversion, and SPRINGMVC default does not support the conversion of this format, so must be
manually configured, custom data type binding to achieve this function. It is relatively simple to apply SPRINGMVC annotations @initbinder and spring-brought Webdatabinder classes and operations directly.
@InitBinder
public void Initbinder (Webdatabinder binder) {
SimpleDateFormat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd");
Dateformat.setlenient (FALSE);
Binder.registercustomeditor (Date.class, New Customdateeditor (DateFormat, true));
}
 
Beanwrapper and PropertyEditor in Springframework