Basic working principle of learning common-bean@utils

xiaoxiao2021-03-06  72

Always unclear how beanutils do the data of Map and Java Beans COPY. Today, I saw that the common-beanutils code found that they used some Class of the Java.beans under the JDK in JDK to complete this feature. There is mainly Java.Beans.Ntrospector and Java.Beans.BeanInfo and Java.Beans.PropertyDescriptor. Beanutils first defines the key in the MAP into the attribute name in the Java Bean, and then find the write method and reading method of the attribute through the property. This makes it easy to complete this Map to Java Bean's data COPY feature. The following code illustrates the use of several Class of Java.beans. Package hello;

Import java.beans.introspector; import java.beans.beanInfo; import java.beans.propertyDescriptor; import java.util.enumert;

Public class hellojspbean {private string sample = "start value";

Private string Sample2 = "start value";

// Access Sample Property Public String getSample () {system.out.println ("getSample ()"); return sample;}

// Access Sample Property public void setsample (String newValue) {system.out.println ("setsample ()"); if (newValue! = Null) {Sample = newValue;}}

转载请注明原文地址:https://www.9cbs.com/read-107418.html

New Post(0)