spring整合mybatisplus2.x详解
Posted dalianpai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring整合mybatisplus2.x详解相关的知识,希望对你有一定的参考价值。
一丶Mp的配置文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring" 7 xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd 8 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd 10 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"> 11 12 13 <!-- 数据源 --> 14 <context:property-placeholder location="classpath:db.properties"/> 15 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 16 <property name="driverClass" value="${jdbc.driver}"></property> 17 <property name="jdbcUrl" value="${jdbc.url}"></property> 18 <property name="user" value="${jdbc.username}"></property> 19 <property name="password" value="${jdbc.password}"></property> 20 </bean> 21 22 <!-- 事务管理器 --> 23 <bean id="dataSourceTransactionManager" 24 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 25 <property name="dataSource" ref="dataSource"></property> 26 </bean> 27 <!-- 基于注解的事务管理 --> 28 <tx:annotation-driven transaction-manager="dataSourceTransactionManager"/> 29 30 31 <!-- 配置SqlSessionFactoryBean 32 Mybatis提供的: org.mybatis.spring.SqlSessionFactoryBean 33 MP提供的:com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean 34 --> 35 <bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"> 36 <!-- 数据源 --> 37 <property name="dataSource" ref="dataSource"></property> 38 <property name="configLocation" value="classpath:mybatis-config.xml"></property> 39 <!-- 别名处理 --> 40 <property name="typeAliasesPackage" value="com.atguigu.mp.beans"></property> 41 42 <!-- 注入全局MP策略配置 --> 43 <property name="globalConfig" ref="globalConfiguration"></property> 44 </bean> 45 46 <!-- 定义MybatisPlus的全局策略配置--> 47 <bean id ="globalConfiguration" class="com.baomidou.mybatisplus.entity.GlobalConfiguration"> 48 <!-- 在2.3版本以后,dbColumnUnderline 默认值就是true --> 49 <property name="dbColumnUnderline" value="true"></property> 50 51 <!-- 全局的主键策略 --> 52 <property name="idType" value="0"></property> 53 54 <!-- 全局的表前缀策略配置 --> 55 <property name="tablePrefix" value="tbl_"></property> 56 </bean> 57 ? 58 <!-- 59 配置mybatis 扫描mapper接口的路径 60 --> 61 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 62 <property name="basePackage" value="com.atguigu.mp.mapper"></property> 63 </bean> 64 65 66 </beans>