Search in sources :

Example 61 with PaginationInnerInterceptor

use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project mybatis-plus-samples by baomidou.

the class MybatisPlusConfig method mybatisPlusInterceptor.

/**
 *	 分页插件
 */
@Bean
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) Bean(org.springframework.context.annotation.Bean)

Example 62 with PaginationInnerInterceptor

use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project mybatis-plus-samples by baomidou.

the class MpJsonConfig method mybatisPlusInterceptor.

@Bean
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) Bean(org.springframework.context.annotation.Bean)

Example 63 with PaginationInnerInterceptor

use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project mybatis-plus-samples by baomidou.

the class DbConfigurations method mybatisPlusInterceptor.

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

Example 64 with PaginationInnerInterceptor

use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project muses by acgist.

the class MyBatisAutoConfiguration method mybatisPlusInterceptor.

@Bean
@ConditionalOnMissingBean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    final 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) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 65 with PaginationInnerInterceptor

use of com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor in project sakura-boot by yanjingfan.

the class MybatisPlusConfig method tenantPaginationInterceptor.

/**
 * 多租户分页
 * @return
 */
@ConditionalOnProperty(prefix = "tenant", name = "column")
@Bean
public MybatisPlusInterceptor tenantPaginationInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    TenantLineInnerInterceptor tenantInnerInterceptor = new TenantLineInnerInterceptor();
    tenantInnerInterceptor.setTenantLineHandler(new TenantLineHandler() {

        @Override
        public Expression getTenantId() {
            // 可将租户id和租户字段放置在请求头中
            try {
                String tenantId = request.getHeader("tenantId");
                if (tenantId == null || "".equals(tenantId.trim())) {
                    return new LongValue(-1);
                }
                return new LongValue(Long.parseLong(tenantId));
            } catch (Exception e) {
                return new LongValue(-1);
            }
        }

        @Override
        public String getTenantIdColumn() {
            return environment.getProperty("tenant.column");
        // 可将租户id和租户字段放置在请求头中
        // return request.getHeader("tenantColumn");
        }

        @Override
        public boolean ignoreTable(String tableName) {
            // 忽略uid-generator模块相关表
            if ("worker_node".equalsIgnoreCase(tableName)) {
                return true;
            }
            return false;
        }
    });
    interceptor.addInnerInterceptor(tenantInnerInterceptor);
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptor;
}
Also used : TenantLineInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor) TenantLineHandler(com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler) Expression(net.sf.jsqlparser.expression.Expression) MybatisPlusInterceptor(com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor) LongValue(net.sf.jsqlparser.expression.LongValue) PaginationInnerInterceptor(com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) Bean(org.springframework.context.annotation.Bean)

Aggregations

PaginationInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor)104 Bean (org.springframework.context.annotation.Bean)95 MybatisPlusInterceptor (com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor)94 OptimisticLockerInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor)15 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)14 BlockAttackInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor)11 TenantLineInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor)6 InnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor)4 TenantLineHandler (com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler)3 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)3 Expression (net.sf.jsqlparser.expression.Expression)3 Order (org.springframework.core.annotation.Order)3 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)2 IllegalSQLInnerInterceptor (com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor)2 LongValue (net.sf.jsqlparser.expression.LongValue)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