JavaBean and javabean Components

Source: Internet
Author: User

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.

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.