本文的前提是,你愿意將頁(yè)面數(shù)據(jù)封裝為一個(gè)對(duì)象(是否封裝還得看實(shí)際情況,如果頁(yè)面數(shù)據(jù)特別少也沒(méi)這個(gè)必要)。
封裝頁(yè)面數(shù)據(jù)是否使用ModelDrivenInterceptor有時(shí)候還真與個(gè)人使用習(xí)慣有點(diǎn)關(guān)系
看下面的實(shí)現(xiàn)action1:
public class VoteAction implements Action, ModelDriven {
。。。。。
/**
* 封裝請(qǐng)求傳入的信息
*/
private Vote vote = new Vote();
。。。。。
/**
*
* @author weip
* @time 19:36:40 2006-5-14
* @return Object
*/
public Object getModel() {
return vote;
}
}
一個(gè)使用ModelDrivenInterceptor的action
還有另一種實(shí)現(xiàn)action2
public class VoteAction implements Action{
。。。。。
/**
* 封裝請(qǐng)求傳入的信息
*/
private Vote vote = new Vote();
。。。。。
/**
*
* @author weip
* @time 19:36:40 2006-5-14
* @return Object
*/
public Object getVote () {
return vote;
}
}
action1和action2效果完全一樣,只不過(guò)實(shí)現(xiàn)起來(lái)還是有少許差別
1) action1 需要配置ModelDrivenInterceptor,且實(shí)現(xiàn)ModelDriven 接口(如果沒(méi)有實(shí)現(xiàn)此接口,那么配置ModelDrivenInterceptor沒(méi)有任何意義),頁(yè)面的傳值很簡(jiǎn)單<input type="text" name="type" />
這樣就可以將type的值注入到vote的type屬性
2)action2不需要配置ModelDrivenInterceptor,但頁(yè)面?zhèn)髦瞪晕⒙闊┮稽c(diǎn)
<input type="text" name="vote.type" />
如果使用form提交也無(wú)所謂,但如果使用url的方式就很累了。到底如何選擇就要看情況了,好像也無(wú)關(guān)緊要