若沒有實現modeldriven的介面,controll的**會比較冗餘,不能實現controll和model**的分離
下面是沒有實現modeldriven介面的suggestaction
1package
dayday.controll;23
import
com.opensymphony.xwork2.actionsupport;
4import
com.opensymphony.xwork2.modeldriven;
5import
dayday.model.product;
6import
dayday.model.suggest;
7import
dayday.service.addsuggest;89
/**10
* created by i am master on 2017/2/22.
11*/
12public
class suggestaction extends
actionsupport
2526
public
void
setsugname(string sugname)
2930
public
string getsugemail()
3334
public
void
setsugemail(string sugemail)
3738
public
string getsugphone()
4142
public
void
setsugphone(string sugphone)
4546
public
string getsugcontent()
4950
public
void
setsugcontent(string sugcontent)
5354
@override
55public string execute()throws
exception
63 }
實現了modeldriven介面的suggestaction介面以後的**
1package
dayday.controll;23
import
com.opensymphony.xwork2.actionsupport;
4import
com.opensymphony.xwork2.modeldriven;
5import
dayday.model.product;
6import
dayday.model.suggest;
7import
dayday.service.addsuggest;89
/**10
* created by i am master on 2017/2/22.
11*/
12public
class suggestaction extends actionsupport implements modeldriven
2324
@override
25public
suggest getmodel()
29 }
明顯**量減少了很多,實現了分離
action實現modeldriven介面執行的原理
1 1). 先會執行 modeldriveninterceptor 的 intercept 方法. 23public string intercept(actioninvocation invocation) throws
exception
21*/
22 object model =modeldriven.getmodel();
23if (model != null
) 27
if(refreshmodelbeforeresult) 30}
31return
invocation.invoke();32}
3334 2). 執行 parametersinterceptor 的 intercept 方法: 把請求引數的值賦給棧頂物件對應的屬性. 若棧頂物件沒有對應的屬性, 則查詢
35值棧中下乙個物件對應的屬性...
3637 3). 注意: getmodel 方法不能提供以下實現. 的確會返回乙個 suggest 物件到值棧的棧頂. 但當前 action
38 的 suggest 成員變數卻是 null
. 39
40public
suggest getmodel()
Struts2中checkboxlist標籤的使用
selectedproducts name product.id list products listvalue name listkey id value 這裡分兩類,首先明確value的值應該是乙個list,用來顯示checkbox內那些需要先打勾 一類,當value的值是是乙個list bea...
Struts2字尾 深入Struts2
一 將action字尾變成html字尾 xmlversion 1.0 encoding utf 8 doctype struts public apache software foundation dtd struts configuration 2.1 en struts include file...
struts2中的 使用
迭代資料時 例如 var var屬性的值代表當前正在遍歷的物件 var存放在map棧 status int getcount 返回當前迭代的元素個數 int getindex 返回當前迭代的元素的索引 boolean iseven 返回當前迭代元素的索引是否是偶數 boolean isodd 返回當...