博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SSH(spring+struts2+hibernate)XML式配置
阅读量:4576 次
发布时间:2019-06-08

本文共 8564 字,大约阅读时间需要 28 分钟。

第一步:pom文件

Struts_2
cn.com
1.0-SNAPSHOT
4.0.0
SSHAnno
war
SSHAnno Maven Webapp
http://maven.apache.org
junit
junit
3.8.1
test
org.springframework
spring-context
4.2.0.RELEASE
org.aspectj
aspectjweaver
1.8.7
org.springframework
spring-web
4.1.8.RELEASE
javaee
javaee-api
5
javax.servlet
jstl
1.2
runtime
org.springframework
spring-tx
4.2.5.RELEASE
com.mchange
c3p0
0.9.5.2
javax.transaction
jta
1.1
org.hibernate
hibernate-core
5.0.6.Final
org.springframework
spring-orm
4.2.2.RELEASE
com.oracle
ojdbc6
11.2.0.1.0
org.apache.struts
struts2-core
2.3.4.1
org.apache.struts.xwork
xwork-core
2.3.4.1
org.apache.struts
struts2-spring-plugin
2.3.4.1
org.apache.struts
struts2-convention-plugin
2.3.4.1
src/main/java
**/*.xml
View Code

第二步:applicationContext.xml文件

org.hibernate.dialect.Oracle10gDialect
true
true
org.springframework.orm.hibernate5.SpringSessionContext
View Code

struts.xml

/jsp/index.jsp
View Code

web.xml

Archetype Created Web Application
contextConfigLocation
classpath:applicationContext.xml
struts
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts
/*
org.springframework.web.context.ContextLoaderListener
View Code

deptAction类

package cn.happy.action;/** * Created by Happy on 2018-03-02. */import cn.happy.entity.Dept;import cn.happy.service.IDeptService;import com.opensymphony.xwork2.Action;/** * 作者:微冷的雨 * * @create 2018-03-02 * 博客地址:www.cnblogs.com/weilengdeyu */public class DeptAction implements Action {    private Dept dept;    IDeptService service;    public String execute() throws Exception {        service.addDept(dept);        return SUCCESS;    }    public Dept getDept() {        return dept;    }    public void setDept(Dept dept) {        this.dept = dept;    }    public IDeptService getService() {        return service;    }    public void setService(IDeptService service) {        this.service = service;    }}
View Code

IDeptDAO接口

package cn.happy.dao;import cn.happy.entity.Dept;/** * Created by Happy on 2018-03-02. */public interface IDeptDAO {    public int addDept(Dept dept);}
View Code

DeptDAOImpl

package cn.happy.dao;/** * Created by Happy on 2018-03-02. */import cn.happy.entity.Dept;import org.hibernate.Session;import org.hibernate.SessionFactory;import java.io.Serializable;/** * 作者:微冷的雨 * * @create 2018-03-02 * 博客地址:www.cnblogs.com/weilengdeyu */public class DeptDAOImpl implements IDeptDAO {    SessionFactory sessionFactory;    public int addDept(Dept dept) {        Session session = sessionFactory.getCurrentSession();        Serializable count = session.save(dept);        return (Integer)count;    }    public SessionFactory getSessionFactory() {        return sessionFactory;    }    public void setSessionFactory(SessionFactory sessionFactory) {        this.sessionFactory = sessionFactory;    }}
View Code

Dept类

package cn.happy.entity;/** * Created by Happy on 2017-10-11. */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;    }}
View Code

Dept.hbm.xml

View Code

IDeptService

package cn.happy.service;import cn.happy.entity.Dept;/** * Created by Happy on 2018-03-02. */public interface IDeptService {    public int addDept(Dept dept);}
View Code

DeptServiceImpl

package cn.happy.service;/** * Created by Happy on 2018-03-02. */import cn.happy.dao.IDeptDAO;import cn.happy.entity.Dept;import org.springframework.transaction.annotation.Transactional;/** * 作者:微冷的雨 * * @create 2018-03-02 * 博客地址:www.cnblogs.com/weilengdeyu */public class DeptServiceImpl implements IDeptService {    IDeptDAO dao;    @Transactional    public int addDept(Dept dept) {        return dao.addDept(dept);    }    public IDeptDAO getDao() {        return dao;    }    public void setDao(IDeptDAO dao) {        this.dao = dao;    }}
View Code

 

转载于:https://www.cnblogs.com/with-lj/p/8508936.html

你可能感兴趣的文章
[转载,感觉写的非常详细]DUBBO配置方式详解
查看>>
Android在Eclipse上的环境配置
查看>>
面向对象(五)
查看>>
android平台下使用点九PNG技术
查看>>
Python学习3,列表
查看>>
最长回文子串
查看>>
JAVA基础-JDBC(一)
查看>>
js中for和while运行速度比较
查看>>
算法第5章作业
查看>>
7.9 练习
查看>>
基于ArcGIS JS API的在线专题地图实现
查看>>
learnByWork
查看>>
lua 函数
查看>>
Git的基本命令
查看>>
四平方和
查看>>
第十八周 12.27-1.2
查看>>
C# IP地址字符串和数值转换
查看>>
TCHAR和CHAR类型的互转
查看>>
常用界面布局
查看>>
C语言—— for 循环
查看>>