码迷,mamicode.com
首页 > 编程语言 > 详细

spring配置和映射文件

时间:2017-12-04 15:04:52      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:poj   ping   doc   public   aspectj   http   固定   ber   ref   

配置

<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://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
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd" default-autowire="byType">
<!-- 配置数据源-连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:195.168.1.195:1521/orcl"></property>
<property name="username" value="t_demo"></property>
<property name="password" value="123456"></property>
<property name="maxActive" value="10"></property>
<property name="maxIdle" value="8"></property>
<property name="minIdle" value="5"></property>
</bean>

<!-- 配置SessionFactory -->
<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 引入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 引入映射文件 -->
<property name="packagesToScan">
<!-- 相当于<mapping class="全限定名" /> -->
<list>
<!-- 给出实体类所在范围 -->
<value>com.oak.entity</value>
</list>
</property>

<!-- 配置参数 -->
<property name="hibernateProperties">
<!-- 集合注入 -->
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- 自动建表key值固定的 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>

<!-- 扫描注解 -->
<context:component-scan base-package="com"></context:component-scan>
<!-- 日志打印 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>

</beans>

映射文件

<?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属性,表示持久化类所在的包 package="com.oak.pojo"
如果此处加了package属性,则class标签的属性name值只写类名即可,
如果hibernate-mapping标签中没加package属性
则class标签的name值为 全限定名(表名+类名)-->
<hibernate-mapping>
<!-- 对应类和表 -->
<class name="com.oak.entity.Goods" table="T_GOODS">
<!-- 对应的属性和字段 -->
<id name="id" column="id">
<generator class="native"></generator>
</id>
<!-- 给非主属性和非主字段 -->
<property name="goodsname" column="goodsname"></property>
<property name="weight" column="weight"></property>
<property name="price" column="price"></property>
<property name="color" column="color"></property>
<property name="shangtime" column="shangtime" type="java.sql.Date"></property>
<property name="stock" column="stock"></property>

<many-to-one name="brand" class="com.oak.entity.Brand">
<column name="BRANDID"></column>
</many-to-one>

<many-to-one name="smc" class="com.oak.entity.SmallClass">
<column name="SID"></column>
</many-to-one>
</class>
</hibernate-mapping>

spring配置和映射文件

标签:poj   ping   doc   public   aspectj   http   固定   ber   ref   

原文地址:http://www.cnblogs.com/love1/p/7976810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!