JavaBean and javabean Components
Condition
1. java class
2. No parameter Constructor
3. All member variables are private
4. public get set
------------------------------------------
Singleton:
1. private Constructor
2. private static Instance Object
3. public static object access method
--------------------------------------------
JavaBean attributes
1. It must start with a lowercase letter.
2. attributes can provide public get and set methods.
* Naming rules: name, getName, and setName
--------------------------
In actual development, Model2 is used, and only a few javaben-related labels are used.
-------------------------
What is introspection?
JDK provides a set of Java Bean operation APIs
Reflection-based.
JavaBean attribute calculation method
1. The getBeanInfo () method of the Introspector class
BeanInfo beanInfo = Introspector. getBeanInfo (Person. class );
Person {
Name, age
GetName
GetAge
SetName
SetAge
}
BeanInfo
1. getMethodDescriptors ()
2. getProperyDescriptors () ------- key
// Obtain all javaben attributes
PropertyDescriptor [] pd = beanInfo. getPropertyDescriptors ();
// Each attribute description represents an attribute of javaben.
Sysout (pd. length); // 4
Because the javaben attribute is calculated not through member variables, but through get and set methods.
For example, getName ------ remove get and lowercase the first letter of Name to get the name attribute.
So there are four.
Every Object inherits the Object and the getClass () method-get the class attribute.
------------------------
BeanUtils Development Kit
BeanUtils. populate (person, request. getParameterMap ());
How can I encapsulate a special Date type in the Person class?
1. Custom Converter ---- Converter interface needs to be implemented
2. register the converter before calling the populate Method
ConvertUtils. register (Converter converter, Class clazz );
Conclusion:
1. If the form parameter is of the String type and the String an attribute is of the String type, call BeanUtils. populate to encapsulate the fomr data.
2. If the javabean attribute type is not string, the form data encapsulation javaben requires a converter-many default converters are provided in BeanUtils API.
3. If the conversion type is special, use the custom converter. Define the class implementation Interface Converter and implement the convert method
Use ConvertUtils. register to register a converter before populate is called.
What is JAVABean?
In the MVC design model, javaBean is also called a model layer. In a general program, we call it a data layer, which is used to set data attributes and some behaviors, then, I will provide the get/set method for obtaining and setting attributes.
What is JAVABean?
In the MVC design model, javaBean is also called a model layer. In a general program, we call it a data layer, which is used to set data attributes and some behaviors, then, I will provide the get/set method for obtaining and setting attributes.