狂淘

          www.kuangtao.net

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            6 隨筆 :: 185 文章 :: 68 評論 :: 0 Trackbacks
          13:18:45
          1.web.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <web-app version="2.4" xmlns=http://java.sun.com/xml/ns/j2ee                          
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
           http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
           
           <!-- struts2 spring 整合 -->
           <listener>
            <listener-class>
             org.springframework.web.context.ContextLoaderListener
            </listener-class>
           </listener>
           <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
             /WEB-INF/classes/applicationContext-*.xml,classpath*:applicationContext-*.xml
            </param-value>
           </context-param>

           <!--  <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
            /WEB-INF/classes/applicationContext.xml
            </param-value>
            </context-param>-->
            
            <!-- 自動關閉Hibernatesession -->
           <filter>
            <filter-name>hibernateFilter</filter-name>
            <filter-class>
             org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
            </filter-class>
           </filter>
           <filter-mapping>
            <filter-name>hibernateFilter</filter-name>
            <url-pattern>/*</url-pattern>
           </filter-mapping>
          <!-- 亂碼 -->
           <filter>
            <filter-name>Spring character encoding filter</filter-name>
            <filter-class>
             org.springframework.web.filter.CharacterEncodingFilter
            </filter-class>
            <init-param>
             <param-name>encoding</param-name>
             <param-value>GBK</param-value>
            </init-param>
           </filter>
           <filter-mapping>
            <filter-name>Spring character encoding filter</filter-name>
            <url-pattern>/*</url-pattern>
           </filter-mapping>

           <!-- struts2.0配置 -->
           <filter>
            <filter-name>struts2</filter-name>
            <filter-class>
             org.apache.struts2.dispatcher.FilterDispatcher
            </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>
          2.  struts2-spring-plugin-2.0.14.jar
          3.applicationContext-actions.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: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-2.5.xsd
             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
          <bean id="loginManger" class="com.xushi.Manager.Impl.LoginSericeImpl"/>
          <bean id="login" class="com.xushi.action.LoginAction">
           <property name="loginManger" ref="loginManger"></property>
          </bean>
          </beans>
          4.applicationContext-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: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-2.5.xsd
             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

          </beans>

          5.applicationContext-common.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: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-2.5.xsd
             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

          <!-- 配置sessionFactory -->
           <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation">
             <value>classpath:hibernate.cfg.xml</value>
            </property>
           </bean> 
           <!-- 配置事務管理器 --> 
           <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
             <ref local="sessionFactory"/>
            </property>
           </bean>
             
              <!-- 配置事務特性 -->      
              <tx:advice id="txAdvice" transaction-manager="transactionManager">
               <tx:attributes>
                <tx:method name="add*" propagation="REQUIRED"/>
                <tx:method name="del*" propagation="REQUIRED"/>
                <tx:method name="update*" propagation="REQUIRED"/>
                <tx:method name="*" read-only="true"/>
               </tx:attributes>
              </tx:advice>
             
              <!-- 配置那些類的方法進行事務管理 -->
              <aop:config>
               <aop:pointcut id="allManagerMethod" expression="execution (* com.xushi.manager.*.*(..))"/>
               <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
              </aop:config>         
          </beans>

          6記住配置ant環境變量
          build.xml



          <?xml version="1.0" encoding="GBK"?>
          <project name="OA【01】系統構建腳本" default="生成Hibernate配置文件" basedir=".">

              <property name="src.dir" value="${basedir}/src"/>
           <property name="xdoclet.home" value="D:/xdoclet-plugins-dist-1.0.4"/>

              <!-- Build classpath -->
              <path id="xdoclet.task.classpath">
                 <fileset dir="${xdoclet.home}/lib">
                    <include name="**/*.jar"/>
                 </fileset>
                <!--   <fileset dir="${xdoclet.home}/plugins">
                    <include name="**/*.jar"/>
                 </fileset>-->
              </path>
           <taskdef 
            name="xdoclet"
            classname="org.xdoclet.ant.XDocletTask"
            classpathref="xdoclet.task.classpath"
           />
           
           <target name="生成Hibernate配置文件">
            <xdoclet>
             <fileset dir="${src.dir}/com/xushi/model">
              <include name="**/*.java"/>
             </fileset>   
             <component
              classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"
              destdir="${src.dir}"
              version="3.0"
              hbm2ddlauto="update"
              jdbcurl="jdbc:mysql://localhost/oa"
              jdbcdriver="com.mysql.jdbc.Driver"
              jdbcusername="root"
              jdbcpassword="wzy"
              dialect="org.hibernate.dialect.MySQLDialect"
              showsql="true"
             />
            </xdoclet>
           </target>
           <target name="生成hibernate映射文件">
            <xdoclet>
             <fileset dir="${src.dir}/com/xushi/model">
              <include name="**/*.java"/>
             </fileset>
             <component
              classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"
              version="3.0"
              destdir="${src.dir}"
             />
            </xdoclet>
           </target>
          </project>


           7.Orgnization.java

          package com.xushi.model;

          import java.util.Set;

          /**
           *
           * @author Administrator
           * @hibernate.class table="T_Orgnization"
           *
           */
          public class Orgnization {
           
           /**
            * @hibernate.id
            *   generator-class="native"
            */
           private int id;

           /**
            * @hibernate.property
            */
           private String name;
           
           /**
            * @hibernate.property
            */
           private String sn;
           
           /**
            * @hibernate.property
            */
           private String description;
           
           /**
            * @hibernate.many-to-one
            *   column="pid"
            */
           private Orgnization parent;
           
           /**
            * @hibernate.set inverse="true" lazy="extra"
            * @hibernate.key column="pid"
            * @hibernate.one-to-many class="com.xushi.model.Orgnization"
            */
           private Set children;
           
           
           public Set getChildren() {
            return children;
           }
           public void setChildren(Set children) {
            this.children = children;
           }
           public String getDescription() {
            return description;
           }
           public void setDescription(String description) {
            this.description = description;
           }
           public int getId() {
            return id;
           }
           public void setId(int id) {
            this.id = id;
           }
           public String getName() {
            return name;
           }
           public void setName(String name) {
            this.name = name;
           }
           public Orgnization getParent() {
            return parent;
           }
           public void setParent(Orgnization parent) {
            this.parent = parent;
           }
           public String getSn() {
            return sn;
           }
           public void setSn(String sn) {
            this.sn = sn;
           }
          }
          8.Person.java

          package com.xushi.model;

          /**
           *
           * @author Administrator
           * @hibernate.class table="T_Person"
           */
          public class Person {
           
           /**
            * @hibernate.id
            *   generator-class="native"
            */
           private int id;
           
           /**
            * @hibernate.property
            */
           private String name;
           
           /**
            * @hibernate.property
            */
           private String sex;
           
           /**
            * @hibernate.property
            */
           private String address;
           
           /**
            * @hibernate.property
            */
           private String duty;
           
           /**
            * @hibernate.property
            */
           private String phone;
           
           /**
            * @hibernate.property
            */
           private String description;
           
           /**
            * @hibernate.many-to-one
            */
           private Orgnization org;
           
           public String getAddress() {
            return address;
           }
           public void setAddress(String address) {
            this.address = address;
           }
           public String getDescription() {
            return description;
           }
           public void setDescription(String description) {
            this.description = description;
           }
           public String getDuty() {
            return duty;
           }
           public void setDuty(String duty) {
            this.duty = duty;
           }
           public int getId() {
            return id;
           }
           public void setId(int id) {
            this.id = id;
           }
           public String getName() {
            return name;
           }
           public void setName(String name) {
            this.name = name;
           }
           public String getPhone() {
            return phone;
           }
           public void setPhone(String phone) {
            this.phone = phone;
           }
           public String getSex() {
            return sex;
           }
           public void setSex(String sex) {
            this.sex = sex;
           }
           public Orgnization getOrg() {
            return org;
           }
           public void setOrg(Orgnization org) {
            this.org = org;
           }
          }

          posted on 2009-10-24 13:19 狂淘 閱讀(537) 評論(0)  編輯  收藏 所屬分類: struts2.0 spring hiberate
          主站蜘蛛池模板: 延寿县| 河间市| 临清市| 玛纳斯县| 泰顺县| 措美县| 颍上县| 科技| 桓台县| 浪卡子县| 建湖县| 天等县| 平远县| 康定县| 兴海县| 玉屏| 常熟市| 东台市| 铜陵市| 阳曲县| 辛集市| 曲松县| 溆浦县| 长子县| 泽州县| 沾益县| 西林县| 呼和浩特市| 前郭尔| 博白县| 西藏| 富顺县| 新昌县| 蒲江县| 肇东市| 阳东县| 大理市| 新绛县| 治县。| 曲沃县| 唐河县|