黑马程序员:SSH2配置详情

来源:互联网 发布:java项目转maven项目 编辑:程序博客网 时间:2024/06/06 04:12

---------------------- ASP.Net+Android+IOS开发.Net培训、期待与您交流! ----------------------

Hibernate(hibernate.cfg.xml)

<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><property name="connection.url">jdbc:oracle:thin:@localhost:1521:mydb</property><property name="dialect">org.hibernate.dialect.Oracle9Dialect</property><property name="myeclipse.connection.profile">mydb</property><property name="connection.username">my</property><property name="connection.password">accp</property><property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property><property name="show_sql">true</property><property name="cache.query_cache_factory">true</property><!-- 没表时自动生成表,create-drop是删了原有重新建create 删数据update更新表结构validate映射表,无报错--><property name="hbm2ddl.auto">update</property><mapping resource="cn/com/bean/Employee.hbm.xml" /></session-factory></hibernate-configuration>


Struts2(struts.xml)

<?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><!--默认的视图主题,用表达式时防止struts为页面加入TD之类标签 --><constant name="struts.ui.theme" value="simple"/><!-- 创建一个常量来让Spring来代替Struts2的工厂来创建action, --><constant name="struts.objectFactory" value="spring"/><!-- 创建一个employee包,继承自Struts 2 的struts-default 包 --><package name="employee" namespace="/employee" extends="struts-default"><!-- 此处因为交给Spring管理class是action bean的名称 --><action name="list" class="employeeAction">    <param name=""></param><result name="list">/WEB-INF/page/employee.jsp</result></action><action name="manage_*" class="employeeManageAction" method="{1}"><result name="add">/WEB-INF/page/employeeAdd.jsp</result><result name="message">/WEB-INF/page/message.jsp</result></action></package></struts>


Spring(beans.xml)

<?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:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"><!-- 扫描加注解,cn.com下面的所有包加快开发速速度 --><context:component-scan base-package="cn.com"/><!--这类, 创建sessionFactory做成单例,spring提供,spring接管事务管理 --><bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!-- 使用Spring提供LocalSessionFactoryBean传入一个Hibernate配置文件的位置 -->  <property name="configLocation">  <value>classpath:hibernate.cfg.xml</value>  </property>  </bean>    <!-- 事务spring用的hibernate事务因为要用底层session.beginTransaction()来开启 -->  <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  <property name="sessionFactory" ref="sessionFactory"/>  </bean>  <!-- spring的事务配置申明:采用两种方法来申明 事务,一种是那些类需,一种是采用注解(这采用,有点高度藕合) -->  <!-- 采用注解方式配置事务 在spring 注册一个专门用解析的处理器(类),来完成-->  <tx:annotation-driven transaction-manager="txManager"/>  <!--  此方法要类中有属性sessionFactory,extends HibernateDaoSupport  <bean id="employeeServiceImpl"   class="cn.com.service.impl.EmployeeServiceImpl">  <property name="sessionFactory" ref="sessionFactory"/>  </bean>   --></beans>


web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><!-- 通过以下就可以在WEB应用下使用Spring容器了 -->  <context-param><!-- 指定配置文件 -->  <param-name>contextConfigLocation</param-name>  <param-value>classpath:beans.xml</param-value>  </context-param>  <!-- 实例化Spring容器 -->  <listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>     <!-- 通过以下来引出struts2 -->  <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>  <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>


实体类(Employee.hbm.xml)

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="com.jboa.entity">    <class name="Employee" table="employee"  >        <id name="id" type="java.lang.String">            <column name="id" length="20" />            <generator class="sequence">            <param name="sequence">seq_employee</param>            </generator>        </id>        <many-to-one name="sysDepartment" class="Department" fetch="select" lazy="false">            <column name="department_id" not-null="true">                <comment>部门</comment>            </column>        </many-to-one>        <many-to-one name="sysPosition" class="Position" fetch="select" lazy="false" >            <column name="position_id" not-null="true" >                <comment>职务编号</comment>            </column>        </many-to-one>        <property name="password" type="java.lang.String">            <column name="password" length="45" not-null="true">                <comment>密码</comment>            </column>        </property>        <property name="name" type="java.lang.String">            <column name="name" length="45" not-null="true">                <comment>姓名</comment>            </column>        </property>        <property name="status" type="java.lang.String">            <column name="status" length="20" not-null="true">                <comment>状态</comment>            </column>        </property>               <set name="claimVouchers" table="claimVoucher" inverse="true">            <key>                <column name="creator_id" length="20" not-null="false">                    <comment>填报人</comment>                </column>            </key>            <one-to-many class="ClaimVoucher" />        </set>        <set name="nextDealBys" table="employee" inverse="true">            <key>                <column name="next_deal_id" length="20" >                    <comment>处理人</comment>                </column>            </key>            <one-to-many class="Employee" />        </set>        <set name="departments" inverse="true">            <key>                <column name="manager_id" length="20" >                    <comment>部门经理/总经理</comment>                </column>            </key>            <one-to-many class="Department" />        </set>        <set name="checkResults" inverse="true">            <key>                <column name="checker_id" length="20" not-null="false">                    <comment>审核人</comment>                </column>            </key>            <one-to-many class="CheckResult" />        </set>    </class></hibernate-mapping>





原创粉丝点击