Java Framework STRUTS2 Data encapsulation

Source: Internet
Author: User

One, Strust2 package data contains two parts:

When the data is in the action class, it passes through the interceptor, which has many functions: such as data encapsulation, type conversion, and so on.

I can view the next Strust-default.xml file to see which interceptors are executed by default.

The interceptor in the default stack in is executed as follows:

Where the Interceptor params and Modeldriven are: Attribute encapsulation and module encapsulation respectively.

1. Attribute Encapsulation

Common: It is important to realize the set method. The interceptor uses the set method to encapsulate the data for us.

1 Package Jd.com.dealdata;2 3  Public classAbdata {4     PrivateString username;5     PrivateString password;6      PublicString datadeal () {7System. out. println ( This. password+ This. username);8         return NULL;9     }Ten  One      Public voidSetusername (String username) { A          This. Username =username; -     } -  the      Public voidSetPassword (String password) { -          This. Password =password; -     } -}

2, module packaging (more commonly used)

1) Preparatory work:

Need to write JavaBean.

Inherited interface: Modeldriven is a generic type that is later encapsulated JavaBean class name.

Implementation method:Getmodel Returns the class of JavaBean.

1 Package JD.com;2 3 import Com.opensymphony.xwork2.ActionSupport;4 import Com.opensymphony.xwork2.ModelDriven;5 6  Public classModal extends Actionsupport implements Modeldriven<user> {7     PrivateUser User =NewUser ();8 @Override9      PublicUser Getmodel () {Ten         returnuser; One     } A  - @Override -      PublicString Execute () throws Exception { theSystem. out. println (user); -         returnNONE; -     } -}

Java Framework STRUTS2 Data encapsulation

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.