spring四天计划(4day)

本文介绍SSH框架整合的具体实现,包括Struts2、Hibernate5.x和Spring4.x的使用。通过整合Struts2作为Web层,Spring作为Service层,Hibernate作为DAO层来实现MVC架构的应用开发。

ssh三大框架整合
(1)struts2
(2)hibernate5.x
(3)spring4.x

ssh框架整合的思想:

web层:struts
|
V
service层(业务逻辑层):spring
|
V
dao层(数据层):hibernate,对数据库进行crud操作

俩个框架整合##:

1.struts和spring整合:

把struts的action对象创建交给spring进行管理

2.spring和hibernat整合:
把hibernate核心配置文件里面的数据库的配置,直接写在spring配置文件中
第一次访问的时候很慢,因为第一次访问的时候创建sessionFactory对象
把sessionFactory对象创建交给spring管理
在服务器启动的时候创建sessionFactory对象

1.把struts2的action交给spring管理

package cn.itcast.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
      @Override
    public String execute() throws Exception {
          System.out.println("action.......");
        return NONE;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd" >
<struts>


    <package name="demo1" extends="struts-default" namespace="/">

       <action name="userAction" class="userAction"></action>

    </package>
</struts>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
    <!-- 配置c3p0连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <!--注入里面的属性值 -->
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="user" value="root"></property>
        <property name="jdbcUrl" value="jdbc:mysql:///spring_day04"></property>
        <property name="password" value="123456"></property>

    </bean>

    <!--配置action对象  -->
    <bean id="userAction" class="cn.itcast.action.UserAction" scope="prototype"></bean>





</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>spring_day04_sshdemo1</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:bean1.xml</param-value>


    </context-param>




      <filter>  
           <filter-name>struts2</filter-name>  
    <!--  注意你的配置,2.5版本直接是filter,不是ng.filter   -->  
             <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>  
     </filter>  

    <filter-mapping>  
      <filter-name>struts</filter-name>  
      <url-pattern>/*</url-pattern>
    </filter-mapping>  

    <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>



  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值