struts2--encapsulated data

There are three ways of data encapsulation in struts2:
1. Attribute encapsulation:
declare the name of the data to be encapsulated in the action class (that is, the value of the name of the input item in the form); generate the set method of the declared class.
In this way, the data to be submitted by the form can be encapsulated into the specified bean object.
The bottom layer uses the operation of the <interceptor-ref name="params"> interceptor
2. ognl expression:
first, declare the name of the data to be encapsulated in the action class (that is, the value of the name of the input item in the form); generate the declaration Class get and set methods;
form attributes are written as <intput type="text" name="data name. JavaBean attribute name">  
3. Implement interface ModelDriven
The name attribute in the form is the JavaBean attribute name; implement ModelDriven in action interface and implement its getModel() method;
create a new JavaBean object in action and return this object in getModel method.
The bottom layer uses the <interceptor-ref name="modelDriven"/> interceptor to operate

The difference between 2 and 3:
2 can encapsulate data into multiple JavaBeans, while 3 cannot.
The way of writing is to declare multiple JavaBeans in the action, and add multiple name attributes to the form [consistent with the attribute names of JavaBeans]

struts2 implements the idea of ​​mvc:
filter: send a request first to the filter, which is used to distribute different requests to different actions [c: controller]
action: not simply M, if it only processes data, it is M, but action is also Responsible for distributing steering then it is C.
result: page returned by action [v: view]

Struts2 encapsulates the data into the list collection:
the name attribute value list[0] of the form input item. The name of the attribute:
username1:<input type="text" name="list[0].username"/>
declare the list in the action Collection, get and set methods to generate list

 

Encapsulate the data into the map collection:
specify which key to set the value
in the form map['key name']. The value of the attribute
declares the map collection in the action, and generates the set and get methods of the map

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326543487&siteId=291194637