• SSH三大框架整合


    导入整合需要的jar包:

      1 !--spring配置-->
      2         <dependency>
      3             <groupId>org.springframework</groupId>
      4             <artifactId>spring-context</artifactId>
      5             <version>4.2.0.RELEASE</version>
      6         </dependency>
      7         <!--aop使用的jar-->
      8         <dependency>
      9             <groupId> org.aspectj</groupId >
     10             <artifactId> aspectjweaver</artifactId >
     11             <version> 1.8.7</version >
     12         </dependency>
     13 
     14         <!--SpringWeb-->
     15         <dependency>
     16             <groupId>org.springframework</groupId>
     17             <artifactId>spring-web</artifactId>
     18             <version>4.1.8.RELEASE</version>
     19         </dependency>
     20 
     21         <!--JavaEE-->
     22         <dependency>
     23             <groupId>javaee</groupId>
     24             <artifactId>javaee-api</artifactId>
     25             <version>5</version>
     26         </dependency>
     27 
     28         <dependency>
     29             <groupId>javax.servlet</groupId>
     30             <artifactId>jstl</artifactId>
     31             <version>1.2</version>
     32             <scope>runtime</scope>
     33         </dependency>
     34 
     35         <dependency>
     36             <groupId>org.springframework</groupId>
     37             <artifactId>spring-tx</artifactId>
     38             <version>4.2.5.RELEASE</version>
     39         </dependency>
     40 
     41         <!--c3p0-->
     42         <dependency>
     43             <groupId>com.mchange</groupId>
     44             <artifactId>c3p0</artifactId>
     45             <version>0.9.5.2</version>
     46         </dependency>
     47 
     48         <!--hibernate jar包-->
     49         <!--jta的jar包-->
     50         <dependency>
     51             <groupId>javax.transaction</groupId>
     52             <artifactId>jta</artifactId>
     53             <version>1.1</version>
     54         </dependency>
     55 
     56         <dependency>
     57             <groupId>org.hibernate</groupId>
     58             <artifactId>hibernate-core</artifactId>
     59             <version>5.0.6.Final</version>
     60         </dependency>
     61 
     62         <!--Spring-ORM-->
     63         <dependency>
     64             <groupId>org.springframework</groupId>
     65             <artifactId>spring-orm</artifactId>
     66             <version> 4.2.2.RELEASE</version>
     67         </dependency>
     68 
     69         <!-- https://mvnrepository.com/artifact/com.oracle/ojdbc6 -->
     70         <dependency>
     71             <groupId>com.oracle</groupId>
     72             <artifactId>ojdbc6</artifactId>
     73             <version>11.1.0.7.0</version>
     74             <scope>test</scope>
     75         </dependency>
     76 
     77 
     78         <dependency>
     79             <groupId>org.apache.struts</groupId>
     80             <artifactId>struts2-core</artifactId>
     81             <version>2.3.4.1</version>
     82         </dependency>
     83 
     84         <dependency>
     85             <groupId>org.apache.struts.xwork</groupId>
     86             <artifactId>xwork-core</artifactId>
     87             <version>2.3.4.1</version>
     88         </dependency>
     89 
     90         <!--Struts整合Spring的jar包-->
     91         <dependency>
     92             <groupId>org.apache.struts</groupId>
     93             <artifactId>struts2-spring-plugin</artifactId>
     94             <version>2.3.4.1</version>
     95         </dependency>
     96 
     97         <!--Struts2注解支持jar包-->
     98         <dependency>
     99             <groupId>org.apache.struts</groupId>
    100             <artifactId>struts2-convention-plugin</artifactId>
    101             <version>2.3.4.1</version>
    102         </dependency>

    然后配置xml文件

    applicationContext.xml:

     1 <!--
     2 1.数据源  c3p0
     3 -->
     4     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
     5         <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
     6         <property name="driverClass" value="${jdbc.driverClass}"></property>
     7         <property name="user" value="${jdbc.username}"></property>
     8         <property name="password" value="${jdbc.password}"></property>
     9     </bean>
    10 
    11     <!--
    12  2.识别到jdbc.properties
    13 -->
    14     <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    15     <!--
    16  3.形成SessionFactory
    17 -->
    18     <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    19         <property name="dataSource" ref="dataSource"></property>
    20         <property name="hibernateProperties">
    21             <props>
    22                 <!--方言-->
    23               <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
    24                 <!--是否打印sql-->
    25                 <prop key="hibernate.show_sql">true</prop>
    26                 <prop key="hibernate.format_sql">true</prop>
    27                 <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
    28             </props>
    29         </property>
    30         <!--关联小配置-->
    31          <property name="mappingDirectoryLocations" value="classpath:cn/happy/entity"></property>
    32     </bean>
    33 
    34     <!--
    35 4.dao
    36 -->
    37      <bean id="deptDao" class="cn.happy.dao.DeptDAOImpl">
    38          <property name="sessionFactory" ref="sessionFactory"></property>
    39      </bean>
    40 <!--
    41 5.service
    42 -->
    43     <bean id="deptService" class="cn.happy.service.DeptServiceImpl">
    44         <property name="dao" ref="deptDao"></property>
    45     </bean>
    46 <!--
    47 6.action
    48 -->
    49     <bean id="deptAction" class="cn.happy.action.DeptAction">
    50         <property name="service" ref="deptService"></property>
    51     </bean>
    52 <!--
    53 
    54 7.事务管理器
    55 -->
    56     <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    57         <property name="sessionFactory" ref="sessionFactory"></property>
    58     </bean>
    59 <!--
    60 8.事务真实配置
    61 -->
    62     <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>

    jdbc.properties:

    struts.xml:

    1 <struts>
    2    <!--修改这个文件的时候,可以自动重新部署-->
    3     <constant name="struts.devMode" value="true" />
    4     <package name="default" namespace="/" extends="struts-default">
    5         <action name="add" class="deptAction">
    6             <result>/jsp/index.jsp</result>
    7         </action>
    8     </package>
    9 </struts>

    开始创建层次

    action层:

    service层:

    DeptServiceimpl:

    IDeptService:

     

    dao层:

    DeptDAOImpl:

    IDeptdAO:

     

    entity层:

     

    Dept:

    Dept.hbm.xml:

     

    配置页面:

     add.jsp:

    部署Tomcat上,然后运行就可以了

  • 相关阅读:
    天翼网关获取超级密码
    Wirte-up:攻防世界Web解题过程新手区01-06
    F#周报2019年第12期
    F#周报2019年第11期
    F#周报2019年第10期
    F#周报2019年第9期
    F#周报2019年第8期
    F#周报2019年第7期
    ML.NET 0.10特性简介
    F#周报2019年第6期
  • 原文地址:https://www.cnblogs.com/anzmri/p/8493496.html
Copyright © 2020-2023  润新知