zoukankan      html  css  js  c++  java
  • spring配置和映射文件

    配置

    <?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>

  • 相关阅读:
    51nod 1574 排列转换(猜结论)
    百度之星资格赛 1005 寻找母串(分块打表+组合数计算)
    百度之星资格赛 1004 度度熊的午饭时光(01背包+最小序号和+字典序+有bug)
    百度之星资格赛 1003 度度熊与邪恶大魔王(二维dp)
    HDU 4542 小明系列故事——未知剩余系 (数论|反素数)
    51nod 1060 最复杂的数(反素数)
    eclipse hadoop环境搭建 查看HDFS文件内容
    Windows jdk安装以及版本切换
    WIN10配置MongoDB
    Oracle 11g R2 for Win10(64位)的安装步骤
  • 原文地址:https://www.cnblogs.com/love1/p/7976810.html
Copyright © 2011-2022 走看看