applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!--
<bean id="a"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation"
   value="classpath:hibernate.cfg.xml">
  </property>
</bean>
-->


<!-- dataSource -->

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
  <property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=epet"/>
  <property name="username" value="sa"/>
  <property name="password" value=""/>
</bean>


<!-- sessionFactory -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
  <property name="dataSource" >
   <ref local="dataSource"/>
  </property>
 
  <property name="mappingResources" >
   <list>
    <value>com/jenter/pet/entity/PetInfo.hbm.xml</value>
    <value>com/jenter/pet/entity/PetDiary.hbm.xml</value>
   </list>
  </property>
 
  <property name="hibernateProperties" >
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
 
</bean>

<!-- Dao -->

<bean id="petDao" class="com.jenter.pet.dao.PetDaoHibImpl">
  <property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- Biz -->

<bean id="petBiz" class="com.jenter.pet.biz.PetBizImpl">
  <property name="petDao" ref="petDao"/>
</bean>

<!-- Action -->

<bean name="/pet" class="com.jenter.pet.action.PetActionAction" id="pet">
  <property name="petBiz" ref="petBiz"/>
</bean>

</beans>

--------------------------------------------------------------------------------------------------------------------------------

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>

<!-- form-beans -->
  <form-beans>
   <form-bean name="petForm" type="com.jenter.pet.form.PetForm" />
  </form-beans>
 
 
<!-- action-mappings -->
  <action-mappings >
     <action path="/pet"
     name="petForm"
     parameter="operate"
     scope="request"
     type="org.springframework.web.struts.DelegatingActionProxy" >
     <forward name="fir" path="/index.jsp"></forward>
     </action>
  </action-mappings>
 
 
<!-- message-resources --> 
<message-resources parameter="com.jenter.pet.action.ApplicationResources" />

<!-- plug-in -->
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:applicationContext.xml"/>
</plug-in>

</struts-config>

-----------------------------------------------------------------------------------------------------------------------------

PetDiary.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">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.jenter.pet.entity.PetDiary" table="PetDiary" schema="dbo" catalog="epet">
        <id name="diaryId" type="java.lang.Integer">
            <column name="diary_id" />
            <generator class="native" />
        </id>
        <many-to-one name="petInfo" class="com.jenter.pet.entity.PetInfo" fetch="select">
            <column name="diary_pet_id" />
        </many-to-one>
        <property name="diaryDate" type="java.util.Date">
            <column name="diary_date" length="23" />
        </property>
        <property name="diaryTitle" type="java.lang.String">
            <column name="diary_title" length="300" />
        </property>
        <property name="diaryWeather" type="java.lang.String">
            <column name="diary_weather" length="30" />
        </property>
        <property name="diaryContext" type="java.lang.String">
            <column name="diary_context" length="7000" />
        </property>
        <property name="diaryIsPublic" type="java.lang.String">
            <column name="diary_is_public" length="3" />
        </property>
        <property name="diaryLastModify" type="java.util.Date">
            <column name="diary_last_modify" length="23" />
        </property>
        <property name="diaryAuthor" type="java.lang.String">
            <column name="diary_author" length="30" />
        </property>
        <property name="diaryAuthorEmail" type="java.lang.String">
            <column name="diary_author_email" length="200" />
        </property>
    </class>
</hibernate-mapping>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值