zoukankan      html  css  js  c++  java
  • Spring集成MyBatis配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    ">
     
     
    <!-- 设置注解配置包扫描位置 -->
    <context:component-scan base-package="cn.zj.mybatis"/>
     
    <!-- 配置读取 db.properties 数据库配置文件 -->
    <context:property-placeholder location="classpath:db.properties"/>
     
    <!-- 配置数据源连接池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
    <property name="maxActive" value="${jdbc.maxActive}"/>
    </bean>
     
     
    <!--
    配置MyBatis框架的 SqlSessionFactoryBean 类,创建
     
    SqlSessionFactory 工厂对象
     
    -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <!-- 1.注入数据源 -->
    <property name="dataSource" ref="dataSource"/>
     
     
    <!-- 2.配置映射文件 -->
    <property name="mapperLocations">
    <array>
    <!-- <value>classpath:cn/zj/mybatis/mapper/UserMapper.xml</value> -->
    <!-- 可以使用通配符 * 读取 目录下面所有的配置文件 -->
    <value>classpath:cn/zj/mybatis/mapper/*Mapper.xml</value>
    </array>
    </property>
     
    <!-- 3. 配置别名使用包扫描 -->
    <property name="typeAliasesPackage" value="cn.zj.mybatis.pojo"/>
     
    <!-- 4.读取mybat-config.xml配置文件,此配置文件可能还会配一些mybatis框架的
    其他个性化配置
    实际项目开发可能不用配置
    -->
    <property name="configLocation" value="classpath:mybatis-config.xml"/>
     
    </bean>
     
    <!-- SqlSession不需要单独配置并创建了,每次功能操作都需要新的SqlSession操作对象
    所以在创建代理对象的自动创建了
    -->
     
    <!-- 创建UserMapper代理对象-创建单个Mapper对象
     
    使用桥梁包 org.mybatis.spring.mapper.MapperFactoryBean<T> 创建 UserMapper代理对象
    -->
     
    <bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
     
    <!-- 注入SqlSessionFacotry对象 -->
    <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
     
    <!-- 注入UserMapper接口类型:底层创建UserMapper的代理对象 -->
    <property name="mapperInterface" value="cn.zj.mybatis.mapper.UserMapper"/>
     
    </bean>
     
    <!-- 批量创建Mapper代理对象 ,使用包扫描创建Mapper代理对象-->
     
     
    </beans>
  • 相关阅读:
    class 类添加属性
    Ajax请求数据data被JSON.stringify()的数据django解码过程
    Python之浏览器的前进或后退
    滚动条-智能等待-富文本
    Python之阶乘代码
    Python之用型号构成一个三角形代码
    C# Dictionary
    使用C#创建Windows服务
    sql取出每月最早的上报的数据
    mvc NPOI导入读取Excel文件
  • 原文地址:https://www.cnblogs.com/ki16/p/11032557.html
Copyright © 2011-2022 走看看