TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
<!-- 先配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=spring"></property>
<property name="username" value="sa"></property>
<property name="password" value="zhangjie"></property>
</bean>
<!-- 在Spring中配置Hibernate -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" destroy-method="destroy">
<!-- SessionFactory实现类 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 该package下所有类都会被当做实体类加载
<property name="annotatedPackages" value="classpath:/com/zhangjie//orm"></property>
-->
<property name="annotatedClasses"> <!-- 配置实体类 -->
<list>
<value>com.zhangjie.spring.orm.Cat</value>
</list>
</property>
<property name="hibernateProperties"> <!-- Hibernate属性 -->
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop> <!-- 输出SQL语句 -->
<prop key="hibernate.format_sql">true</prop> <!-- 格式化SQL语句 -->
<prop key="hibernate.hbm2ddl.auto">create</prop> <!-- 创建表结构 -->
</props>
</property>
</bean>
<!-- 将sessionFactory使用到Dao中 -->
<bean id="catDao" class="com.zhangjie.spring.orm.CatDaoImpl"> <!-- Dao对象 --> <property name="sessionFactory" ref="sessionFactory"></property> <!-- 设置SessionFactory -->
</bean>
|
|