最近换了一家公司,公司几乎所有的项目都采用的是Struts2+Spring+Ibatis+Oracle的架构,上一个东家一般用的就是JSF+Spring,所做的项目没有一个用过ORM的框架,至于Struts2也只是平时自己做做Demo玩玩,毕竟才出校园,不懂得东西还有太多太多,经过这么几天的摸索,对这套环境的搭建还算比较熟悉了,因此写一篇日志全当自我总结,也可以给那些初次接触这些框架的朋友一点小小小小小小的建议,当然文中的不足还望各位大神指出,帮助小弟快速地成长。

这个Demo的所有jar包我都上传上来了,有兴趣或者有需要的朋友可以直接下载。

http://pan.baidu.com/share/link?shareid=582164770&uk=772999987

开发环境是JDK1.6+Tomcat6.0

好了,不多说了,先上个项目的结构图。

浅谈一下SSI+Oracle框架的整合搭建

 

让我先按照Action-Service-Dao的顺序把所有的层的代码贴出来。

PS:这个Demo起初我是为了测试spring整合ibatis的事务管理,所以只有增删改的方法,并且测试数据都是写死在代码里的,有兴趣的朋友可以添加更多的方法和完善页面

 

首先是Action层:

package com.ssi.test.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.ssi.test.exception.TestException;
import com.ssi.test.svc.TestSvcIfc;

public class TestAction extends ActionSupport {

    private TestSvcIfc testSvc;

    public void setTestSvc(TestSvcIfc testSvc) {
        this.testSvc = testSvc;
    }

    //添加测试数据
    public String addTest() {
        try {
            testSvc.addTest();
        } catch (TestException e) {
            //所有异常集中在Action层处理
            ServletActionContext.getRequest().setAttribute("msg",
                    e.getMessage());
            return ERROR;
        }
        return null;
    }

    //删除测试数据
    public String deleteTest() {
        try {
            testSvc.deleteTest();
        } catch (TestException e) {
            //所有异常集中在Action层处理
            ServletActionContext.getRequest().setAttribute("msg",
                    e.getMessage());
            return ERROR;
        }
        return null;
    }

    //更新测试数据
    public String updateTest() {
        try {
            testSvc.updateTest();
        } catch (TestException e) {
            //所有异常集中在Action层处理
            ServletActionContext.getRequest().setAttribute("msg",
                    e.getMessage());
            return ERROR;
        }
        return null;
    }
}
TestAction.java

相关文章:

  • 2021-07-15
  • 2021-04-26
  • 2021-12-18
  • 2022-01-08
  • 2021-07-05
  • 2022-12-23
  • 2021-08-21
  • 2021-09-07
猜你喜欢
  • 2021-10-24
  • 2021-08-20
  • 2022-03-06
  • 2021-06-16
  • 2022-12-23
  • 2021-12-13
  • 2021-08-04
相关资源
相似解决方案