SSH第一篇【整合SSH步骤、OpenSessionInView】

这篇博客详细介绍了如何整合Struts2、Hibernate和Spring(SSH)框架,包括引入jar文件、配置Web.xml和各个Spring配置文件,以及编写Entity、Dao、Service和Action。在整合过程中特别提到了OpenSessionInView模式,解释了由于事务关闭导致JSP页面无法获取懒加载数据的问题,并指导如何通过配置解决这个问题。
摘要由CSDN通过智能技术生成

前言

到目前为止,Struts2、Hibernate、Spring框架都过了一遍了。也写过了Spring怎么与Struts2整合,Spring与Hibernate整合…本博文主要讲解SSH的整合

整合步骤:

  • 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

需求:员工与部门之间的关系。当操作员工的时候,可以得到员工所在的部门


引入jar文件

这里写图片描述

配置文件

web.xml配置文件

初始化struts功能、spring容器


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">


    <!--初始化Struts功能-->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--初始化Spring容器-->

    <!-- 2. spring 配置 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/bean*</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

Struts.xml

配置请求路径与映射action的关系【记得继承着struts-default】


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <package name="aaa" extends="struts-default">


    </package>
</struts>

SpringIOC容器配置

该Spring配置文件配置着一些公用的信息


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值