zoukankan      html  css  js  c++  java
  • MyBatis整合Spring编码

    MyBatis整合Spring编码

    创建spring包,编写spring-Dao.xml文件

    Spring-Dao.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:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
       <!-- 配置整合mybatis过程 -->
       <!-- 1.配置数据库相关参数properties的属性:${url} -->
       <context:property-placeholder location="classpath:jdbc.properties" />

       <!-- 2.数据库连接池 -->
       <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
            init-method="init" destroy-method="clone">
          <!-- 基本属性driverClassName、 url、user、password -->
          <property name="driverClassName" value="${jdbc.driver}" />
          <property name="url" value="${jdbc.url}" />
          <property name="username" value="${jdbc.username}" />
          <property name="password" value="${jdbc.password}" />

          <!-- 配置初始化大小、最小、最大 -->
          <!-- 通常来说,只需要修改initialSize、minIdle、maxActive -->
          <!-- 初始化时建立物理连接的个数,缺省值为0 -->
          <property name="initialSize" value="${jdbc.initialSize}" />
          <!-- 最小连接池数量 -->
          <property name="minIdle" value="${jdbc.minIdle}" />
          <!-- 最大连接池数量,缺省值为8 -->
          <property name="maxActive" value="${jdbc.maxActive}" />

          <!-- 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁。 -->
          <property name="maxWait" value="${jdbc.maxWait}" />
       </bean>
       <!--<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">-->
          <!--<!– 配置连接池属性 –>-->
          <!--<property name="driverClass" value="${jdbc.driver}" />-->
          <!--<property name="jdbcUrl" value="${jdbc.url}" />-->
          <!--<property name="user" value="${jdbc.username}" />-->
          <!--<property name="password" value="${jdbc.password}" />-->

          <!--<!– c3p0连接池的私有属性 –>-->
          <!--<property name="maxPoolSize" value="30" />-->
          <!--<property name="minPoolSize" value="10" />-->
          <!--<!– 关闭连接后不自动commit –>-->
          <!--<property name="autoCommitOnClose" value="false" />-->
          <!--<!– 获取连接超时时间 –>-->
          <!--<property name="checkoutTimeout" value="10000" />-->
          <!--<!– 当获取连接失败重试次数 –>-->
          <!--<property name="acquireRetryAttempts" value="2" />-->
       <!--</bean>-->

       <!-- 3.配置SqlSessionFactory对象 -->
       <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
          <!-- 注入数据库连接池 -->
          <property name="dataSource" ref="dataSource" />
          <!-- 配置MyBaties全局配置文件:mybatis-config.xml -->
          <property name="configLocation" value="classpath:mybatis-config.xml" />
          <!-- 扫描entity包 使用别名 -->
          <property name="typeAliasesPackage" value="org.secKill.entity" />
          <!-- 扫描sql配置文件:mapper需要的xml文件 -->
          <property name="mapperLocations" value="classpath:mapper/*.xml" />
       </bean>

       <!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到soring容器中 -->
       <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
          <!-- 注入sqlSessionFactory -->
          <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
          <!-- 给出需要扫描Dao接口包 -->
          <property name="basePackage" value="org.secKill.dao" />
       </bean>

       <!--<!– RedisDao –>-->
       <!--<bean id="redisDao" class="org.secKill.dao.cache.RedisDao">-->
          <!--<constructor-arg index="0" value="localhost" />-->
          <!--<constructor-arg index="1" value="6379" />-->
       <!--</bean>-->

    </beans>

  • 相关阅读:
    CocosCreator 手动设置刚体接触回调函数
    CocosCreator 组件添加依赖的其它组件
    Cocos Creator 动画控制
    Cocos Creator Editor 扩展右键菜单
    CocosCreator 代码添加点击事件函数
    jsfl 读取xml
    Markdown 箭头
    Markdown 数学公式输入
    Cocos Creator Editor 创建.anim文件
    VS2017调试技巧
  • 原文地址:https://www.cnblogs.com/sinceForever/p/8454387.html
Copyright © 2011-2022 走看看