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

    mybatis整合Spring的核心代码

    spring-dao.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3        xmlns:context="http://www.springframework.org/schema/context"
     4        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     5        xsi:schemaLocation="http://www.springframework.org/schema/beans
     6        http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
     7        http://www.springframework.org/schema/context
     8        http://www.springframework.org/schema/context/spring-context-4.2.xsd">
     9     <!--配置整合mybatis过程-->
    10     <!-- 1:配置数据库相关参数properties的属性:${url} -->
    11     <context:property-placeholder location="classpath:jdbc.properties"/>
    12     <!--2:数据库连接池-->
    13     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    14         <!--配置连接池属性-->
    15         <property name="driverClass" value="${jdbc.driver}"/>
    16         <property name="jdbcUrl" value="${jdbc.url}"/>
    17         <property name="user" value="${jdbc.username}"/>
    18         <property name="password" value="${jdbc.password}"/>
    19 
    20         <!--c3p0连接池的私有属性-->
    21         <property name="maxPoolSize" value="30"/>
    22         <property name="minPoolSize" value="10"/>
    23         <!--关闭连接后不自动commit-->
    24         <property name="autoCommitOnClose" value="false"/>
    25         <!--获取连接超时时间-->
    26         <property name="checkoutTimeout" value="1000"/>
    27          <!--当获取连接失败重试次数-->
    28         <property name="acquireRetryAttempts" value="2"/>
    29     </bean>
    30 
    31     <!--约定大于配置-->
    32     <!--3:配置SqlSessionFactory对象-->
    33     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    34         <!--注入数据库连接池-->
    35         <property name="dataSource" ref="dataSource"/>
    36         <!--配置MyBatis全局配置文件:mybatis-config.xml-->
    37         <property name="configLocation" value="classpath:mybatis-config.xml"/>
    38         <!--扫描entity包 使用别名 org.seckill.entity.Seckill->Seckill-->
    39         <property name="typeAliasesPackage" value="org.seckill.entity"/>
    40         <!--扫描sql配置文件:mapper需要的xml文件-->
    41         <property name="mapperLocations" value="classpath:mapper/*.xml"/>
    42     </bean>
    43     <!--4:配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中-->
    44     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    45         <!--注入sqlsessionFactory-->
    46         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    47         <!--给出需要扫描Dao接口包-->
    48         <property name="basePackage" value="org.seckill.dao"/>
    49     </bean>
    50 </beans>
  • 相关阅读:
    C#Webform 控件
    C#Webform
    MVC Razor 语法
    input file 添加
    ajax
    jquery动画
    jquery选择器,事件 dom操作
    linq 复杂查询
    webform(linq增删改查)
    asp.net内置对象
  • 原文地址:https://www.cnblogs.com/songsongblue/p/10172624.html
Copyright © 2011-2022 走看看