Search in sources :

Example 1 with MybatisPlusInterceptor

use of com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor in project diboot by dibo-software.

the class CoreAutoConfig method mybatisPlusInterceptor.

/**
 * Mybatis-plus分页插件
 */
@Bean
@ConditionalOnMissingBean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
    return interceptor;
}
Also used : MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with MybatisPlusInterceptor

use of com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor in project springboot-demo by small-rose.

the class MybatisPlusConfig method mybatisPlusInterceptor.

/**
 * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置
 * MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题
 */
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptor;
}
Also used : MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 3 with MybatisPlusInterceptor

use of com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor in project c4p by xseuen.

the class MybatisPlusConfig method mybatisPlusInterceptor.

// 最新版
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptor;
}
Also used : MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 4 with MybatisPlusInterceptor

use of com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor in project Open-Job by lijunping365.

the class MyBatisPlusConfig method mybatisPlusInterceptor.

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    final MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
    // 分页插件
    mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    // 乐观锁插件
    mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
    // sql性能规范插件
    // mybatisPlusInterceptor.addInnerInterceptor(new IllegalSQLInnerInterceptor());
    // 防止全表更新与删除插件
    mybatisPlusInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
    return mybatisPlusInterceptor;
}
Also used : BlockAttackInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor) MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) OptimisticLockerInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with MybatisPlusInterceptor

use of com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor in project jeecg-boot by jeecgboot.

the class MybatisPlusSaasConfig method mybatisPlusInterceptor.

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    // 先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor
    interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {

        @Override
        public Expression getTenantId() {
            String tenant_id = oConvertUtils.getString(TenantContext.getTenant(), "0");
            return new LongValue(tenant_id);
        }

        @Override
        public String getTenantIdColumn() {
            return TENANT_FIELD_NAME;
        }

        // 返回 true 表示不走租户逻辑
        @Override
        public boolean ignoreTable(String tableName) {
            for (String temp : tenantTable) {
                if (temp.equalsIgnoreCase(tableName)) {
                    return false;
                }
            }
            return true;
        }
    }));
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
    return interceptor;
}
Also used : TenantLineInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor) TenantLineHandler(com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler) MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) LongValue(net.sf.jsqlparser.expression.LongValue) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) Bean(org.springframework.context.annotation.Bean)

Aggregations

MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)113 Bean (org.springframework.context.annotation.Bean)110 PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)94 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)18 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)15 BlockAttackInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor)13 TenantLineInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor)7 TenantLineHandler (com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler)4 InnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor)4 Order (org.springframework.core.annotation.Order)4 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)3 Expression (net.sf.jsqlparser.expression.Expression)3 LongValue (net.sf.jsqlparser.expression.LongValue)3 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)2 IllegalSQLInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor)2 StringValue (net.sf.jsqlparser.expression.StringValue)2 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)2 ConditionalOnExpression (org.springframework.boot.autoconfigure.condition.ConditionalOnExpression)2 TenantLineHandler (com.albedo.java.plugins.database.handler.TenantLineHandler)1 SchemaInterceptor (com.albedo.java.plugins.database.interceptor.SchemaInterceptor)1