SSH框架整合

来源:互联网 发布:快速减肥 知乎 编辑:程序博客网 时间:2024/05/19 17:08

 

SSH整合

web应用的三层为:

    1.1 web层,(struts2),Struts2框架用的最多的是action

    1.2 service层(spring),spring中用的最多的是IOC和AOP,把对象的创建交给Spring进行管理

    1.3 dao层(hibernate),hibernate则是用来操作数据库,进行CRUD


SpringStruts整合

SpringHibernate整合

需求:

JSP页面显示员工信息  (查询)

整合步骤:

1) 引入SSH Jar文件

Struts 核心jar

Hibernate 核心jar

Spring

Core  核心功能

Web  web模块支持

Aop   aop支持

Orm   hibernate支持

Jdbc/tx  jdbc支持包、事务相关包

 

2)配置 

Web.xml

初始化struts功能、spring容器

Struts.xml   配置请求路径与映射action的关系

Spring.xml  IOC容器配置

bean-base.xml     【公用信息】

bean-service.xml

bean-dao.xml

bean-action.xml

 

3)开发

Entity/Dao/service/action


步骤一:导入SSH整合需要的jar包




步骤二:编写entity层的Dept,Employee类,以及相关的配置文件Dept.hbm.xml ,Employee.hbm.xml

                    dao层的EmployeeDao类

                    service层的EmployeeService类

                    action层的EmployeeAction类

                     以及相关的bean.xml配置文件
















EmployeeDao类






EmployeeService类




EmployeeAction类




相关的bean-entity.xml



bean-dao.xml




bean-service.xml




bean-action.xml



bean-base.xml





步骤三:配置web.xml  以及struts.xml




struts.xml






步骤四:编写index.jsp页面




最后查看运行出来的结果


数据库:



访问:http://localhost:8080/ssh/employee/show.action





项目操作过程中,可能会遇到 懒加载的异常。(针对这个异常单独列出三种方式解决)