« | October 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | |
| 公告 |
本博客在此声明所有文章均为转摘,只做资料收集使用。并无其他商业用途。 |
Blog信息 |
blog名称: 日志总数:210 评论数量:205 留言数量:-19 访问次数:923967 建立时间:2007年5月10日 |

| |
[webwork]webwork中实现扩展用例方案1 文章收藏, 网上资源, 软件技术, 电脑与网络
李小白 发表于 2007/6/1 16:17:05 |
lhwork 发表于 2006-6-29 14:18:50
背景: 产品一期已经上线,二期必然有很多改动,其中有一处是在原有工作流中引入新的工作流,说白了就是在原先做好某个页面上加入一块新的内容,通常你会去修改你的原先的 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以实现注入,虽然是很小的表现改动,但还是不爽,如何能做到更加完美的插件效果,看方案下集 |
|
|