码迷,mamicode.com
首页 > 编程语言 > 详细

ssh整合(spring + struts2 + hibernate)xml版

时间:2017-10-29 18:42:13      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:src   tle   lis   private   mys   ace   3.0   XML   work   

1.1分层

技术分享

 

1.2jar节点

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <!--spring配置-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.0.RELEASE</version>
        </dependency>
        <!--aop使用的jar-->
        <dependency>
            <groupId> org.aspectj</groupId >
            <artifactId> aspectjweaver</artifactId >
            <version> 1.8.7</version >
        </dependency>

        <!--SpringWeb-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.1.8.RELEASE</version>
        </dependency>

        <!--JavaEE-->
        <dependency>
            <groupId>javaee</groupId>
            <artifactId>javaee-api</artifactId>
            <version>5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

        <!--c3p0-->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.2</version>
        </dependency>

        <!--hibernate jar包-->
        <!--jta的jar包-->
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.0.6.Final</version>
        </dependency>

        <!--Spring-ORM-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version> 4.2.2.RELEASE</version>
        </dependency>




        <!--mysql数据库-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.31</version>
        </dependency>
        <!--Struts整合Spring的jar包-->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.3.4.1</version>
        </dependency>

        <!--Struts2注解支持jar包-->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>2.3.4.1</version>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

2.1. DeptAction 

技术分享
public class DeptAction extends ActionSupport {
    private Dept dept;
    private IDeptService deptService;
    public String add(){
        System.out.println(dept);
        deptService.addDept(dept);
        return SUCCESS;
    }

    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    public IDeptService getDeptService() {
        return deptService;
    }

    public void setDeptService(IDeptService deptService) {
        this.deptService = deptService;
    }
}
技术分享

2.2.Dept 

技术分享
public class Dept {
    private Integer deptno;
    private String deptname;

    public Integer getDeptno() {
        return deptno;
    }

    public void setDeptno(Integer deptno) {
        this.deptno = deptno;
    }

    public String getDeptname() {
        return deptname;
    }

    public void setDeptname(String deptname) {
        this.deptname = deptname;
    }
}
技术分享

 

 2.3.Dept.hbm.xml

技术分享
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.bdqn.bean">
    <class name="Dept" table="Dept">
        <id name="deptno" column="deptno">
            <generator class="native"></generator>
        </id>
            <property name="deptname" />
    </class>
</hibernate-mapping>
技术分享

 

 2.4. IDeptDAO 

public interface IDeptDAO {
    //添加部门的方法
    public int addDept(Dept dept);

}

 

 2.5.DeptDAOImpl 

技术分享
public class DeptDAOImpl implements IDeptDAO{
    private SessionFactory sessionFactory;

    public int addDept(Dept dept) {
        Serializable count = sessionFactory.getCurrentSession().save(dept);
        return (Integer) count;
    }

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public List<Dept> findAll() {
        return sessionFactory.getCurrentSession().createQuery("from Dept").list();
    }

}
技术分享

 

 2.6.IDeptService

public interface IDeptService {
    public void addDept(Dept dept);
}

2.7 DeptServiceImpl 

技术分享
public class DeptServiceImpl implements IDeptService{
    private IDeptDAO deptDAO;
    @Transactional
    public void addDept(Dept dept) {
        deptDAO.addDept(dept);
    }

    public IDeptDAO getDeptDAO() {
        return deptDAO;
    }

    public void setDeptDAO(IDeptDAO deptDAO) {
        this.deptDAO = deptDAO;
    }
}
技术分享

 

ssh整合(spring + struts2 + hibernate)xml版

标签:src   tle   lis   private   mys   ace   3.0   XML   work   

原文地址:http://www.cnblogs.com/hfddz/p/7750454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!