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