webwork中实现扩展用例方案1

背景:
产品一期已经上线,二期必然有很多改动,其中有一处是在原有工作流中引入新的工作流,说白了就是在原先做好某个页面上加入一块新的内容,通常你会去修改你的原先的 service使得其多返回一块数据,或者改变action的内容使其调用某个新的service(这样做不好),如果改变频繁,你会不断的修改以前的东西,其实完全可以拦截器来隔离关注点,这样的话你的修改不会干扰的以前的内容,如果你的修改的东西下一期又不要了,也不要紧,在配制文件中去掉这个拦截器就行了

废话说了一堆,进入实战,看看方案一
step 1)写ListTopVideosContributedIntercept类
public class ListTopVideosContributedIntercept implements Interceptor {
。。。。。。
public String intercept(ActionInvocation invocation) throws Exception {
// 获取service
TopVideosContributedBySelfService topVideosContributedBySelfService = (TopVideosContributedBySelfService) SpringBeanProxy
.getBean("topVideosContributedBySelfService");

// 获取形参1
HttpServletRequest request = ServletActionContext.getRequest();
String userNo = request.getParameter("userNo");

// 调用service
List list = topVideosContributedBySelfService.getTopnVideos(userNo);

// 结果放入值栈
OgnlValueStack stack = ServletActionContext.getContext()
.getValueStack();
stack.setValue("topVideosContributedList", list);

// 返回
return invocation.invoke();
}
。。。。。
}

step2)改变以前的action
加入以下内容:
private List topVideosContributedList;
/**
*
* @author weip
* @time 2006-6-8 9:56:08
* @return List
*/
public List getTopVideosContributedList() {
return topVideosContributedList;
}

/**
*
* @author weip
* @time 2006-6-8 9:56:12
* @param topVideosContributedList List
*/
public void setTopVideosContributedList(List topVideosContributedList) {
this.topVideosContributedList = topVideosContributedList;
}

主要是加入一个属性,以便注入数据

3)修改配置文件
<action name="tvuserinfo" class="moxtv.central.web.action.tvuserinfo.TVUserInfoAction">
<result name="success" type="freemarker">/cn/tvuserinfo/tvuserinfo.ftl</result>
<result name="error" type="freemarker">/cn/tvuserinfo/tvuserinfo_error.ftl</result>
<interceptor-ref name="defaultWebStack" />
<interceptor-ref name="listtopcontribitors" />
<interceptor-ref name="listtopvideoscontributed" />
</action>
加入红色的那一行

这样的话就直接通过拦截器实现了数据的表现,不会干扰以前的内容,有很好的即插即用效果,但有一点不好
需要改变原有的action以实现注入,虽然是很小的表现改动,但还是不爽,如何能做到更加完美的插件效果,看方案下集
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值