Beginner easy to get started with SSH-struts2 03 Data encapsulation, easy to get started with ssh-struts2

Source: Internet
Author: User

Beginner easy to get started with SSH-struts2 03 Data encapsulation, easy to get started with ssh-struts2

In this chapter, we can obtain data to see what is different from the previous chapter. There are also three data encapsulation methods. Next we will introduce them one by one.

First: attribute encapsulation.

Class. There are two attributes: name and pwd. Enter getter and setter for these two attributes.

 

The page uses the login. jsp in the previous chapter. You only need to change the submitted address and configure struts. xml to get the data. Configuration has been introduced before the first two chapters.

The second type: Model driver: The action class implements the ModelDriven interface and the getModel method of the ModelDriven interface.

Privatize an object. This object is returned in the getModel method.

Last: expression Encapsulation

01 declare the object class in the Action class (note that only the object class is declared ),

02: generate the set and get methods for object names of object classes,

03: Modify the attribute value of a form:
Name = "Object name. property name" (users. username)

There are two encapsulation methods after the three methods, which are encapsulated into the List and Map sets.

1. List Set

Page:

Action:

Map set:
Page:

Action:

Note: In an action, attribute encapsulation and model encapsulation cannot be used for the same form. If an action is used, only model driver encapsulation is executed.

Similarities and differences between expression encapsulation and model encapsulation:

Similarities:
Data can be encapsulated into Entity classes.

Differences:
Model encapsulation can only encapsulate data into one entity class, and only one ModelDriven interface can be implemented once in one action. Therefore, model encapsulation can only encapsulate one object class.

Expression encapsulation can encapsulate data into multiple objects.

I have not introduced much about Data encapsulation.

Related Article

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.