本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7585387
建立时间:2006年5月29日




[WebWork]webwork中实现扩展用例方案1
软件技术,  电脑与网络

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以实现注入,虽然是很小的表现改动,但还是不爽,如何能做到更加完美的插件效果,看方案下集


阅读全文(4691) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144755339 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号