MyBatisPlusConfig.java 1.3 KB
Newer Older
Q
qinyingjie 已提交
1 2 3 4 5 6 7 8 9 10 11
package com.kwan.springbootkwan.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

Q
qinyingjie 已提交
12 13 14 15 16 17 18
/**
 * mybatisplus配置
 *
 * @author : qinyingjie
 * @version : 2.2.0
 * @date : 2022/12/19 16:11
 */
Q
qinyingjie 已提交
19 20 21 22 23 24
@MapperScan("com.kwan.springbootkwan.mapper")//扫描我们的mapper文件夹 这里添加了@MapperScan注解就不需要Springboot启动类上加入@MapperScan注解了
@EnableTransactionManagement //事务控制
@Configuration //配置类
public class MyBatisPlusConfig {

    @Bean
Q
qinyingjie 已提交
25
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
Q
qinyingjie 已提交
26 27 28 29 30 31 32 33
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //注册乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}