欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

spring-mybatis整合

程序员文章站 2022-07-04 09:39:35
spring-mybatis配置:

依赖导入:

		<dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>
        <!-- mybatis-plus 依赖 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>2.3</version>
            <exclusions>
                <exclusion>
                    <artifactId>mybatis-spring</artifactId>
                    <groupId>org.mybatis</groupId>
                </exclusion>
            </exclusions>
        </dependency>

spring-mybatis配置:

<?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" xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">

    <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
        <!-- 数据源 -->
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
        <property name="mapperLocations" value="classpath*:com/gogbuy/newversion/*/mapping/*.xml" />
    	<!-- 插件注册 -->
    	<property name="plugins">
    		<list>
    			<!-- 注册分页插件 -->
    			<bean class="com.github.pagehelper.PageInterceptor"></bean>
    			<bean class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"></bean>
    		</list>
    	</property>
    </bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    	<property name="basePackage" value="com.gogbuy.newversion.*" />
    	<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
    </bean>
    
    <!-- 配置事务管理器 -->
    <bean id="transactionManagerForMybatis" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    	<property name="dataSource" ref="dataSource_jeecg" />
    </bean>
    
    <!--开启事务注解-->
    <tx:annotation-driven transaction-manager="transactionManagerForMybatis"></tx:annotation-driven>
    
    <!-- 拦截器方式配置事物 -->
    <!--<tx:advice id="transactionAdvice1" transaction-manager="transactionManager1">
    	<tx:attributes>
    		<tx:method name="add*" propagation="REQUIRED" />
    		<tx:method name="append*" propagation="REQUIRED" />
    		<tx:method name="insert*" propagation="REQUIRED" />
    		<tx:method name="save*" propagation="REQUIRED" />
    		<tx:method name="update*" propagation="REQUIRED" />
    		<tx:method name="modify*" propagation="REQUIRED" />
    		<tx:method name="edit*" propagation="REQUIRED" />
    		<tx:method name="delete*" propagation="REQUIRED" />
    		<tx:method name="remove*" propagation="REQUIRED" />
    		<tx:method name="repair" propagation="REQUIRED" />
    		<tx:method name="delAndRepair" propagation="REQUIRED" />
    		<tx:method name="do*" propagation="REQUIRED" />
    
    		<tx:method name="get*" propagation="SUPPORTS" />
    		<tx:method name="find*" propagation="SUPPORTS" />
    		<tx:method name="load*" propagation="SUPPORTS" />
    		<tx:method name="search*" propagation="SUPPORTS" />
    		<tx:method name="datagrid*" propagation="SUPPORTS" />
    
    		<tx:method name="*" propagation="SUPPORTS" />
    	</tx:attributes>
    </tx:advice>
    <aop:config>
    	<aop:pointcut id="transactionPointcut1" expression="execution(* com.gogbuy.newversion.*.service.*.*(..))" />
    	<aop:advisor pointcut-ref="transactionPointcut1" advice-ref="transactionAdvice1" />
    </aop:config>-->

</beans>

本文地址:https://blog.csdn.net/Stark_liu/article/details/108993200