package cn.cslg.report.common.config;

import cn.cslg.report.common.config.InnerInterceptor.LizzMybatisIntercepts;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
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;

@Configuration
@MapperScan("cn.cslg.report.mapper")
public class MybatisPlusConfig {
    //必须加Bean注解，否则无法拦截器里无法实例化serve
    @Bean
    //自定义拦截器
    public LizzMybatisIntercepts lizzMybatisIntercepts() {
        return new LizzMybatisIntercepts();
    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        interceptor.addInnerInterceptor(lizzMybatisIntercepts());//加入自定义拦截器
        return interceptor;
    }
}
