Search in sources :

Example 11 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project kms by mahonelau.

the class MybatisPlusConfig method paginationInterceptor.

/**
 * 多租户属于 SQL 解析部分,依赖 MP 分页插件
 */
@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor().setLimit(-1);
    // 多租户配置 配置后每次执行sql会走一遍他的转化器 如果不需要多租户功能 可以将其注释
    tenantConfig(paginationInterceptor);
    return paginationInterceptor;
}
Also used : PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 12 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project wakaka by Crysmart.

the class MyBatisConfig method paginationInterceptor.

/**
 * MP 自带分页插件
 * @return
 */
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor page = new PaginationInterceptor();
    page.setDialectType("mysql");
    return page;
}
Also used : PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)

Example 13 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project spring-boot-web by wangchengming666.

the class MybatisPlusConfig method paginationInterceptor.

/**
 * mybatis-plus分页插件<br>
 * 文档:http://mp.baomidou.com<br>
 */
@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    paginationInterceptor.setDialectType("mysql");
    return paginationInterceptor;
}
Also used : PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 14 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project ddf-common by dongfangding.

the class MyBatisConfig method paginationInterceptor.

/**
 * 分页与攻击 SQL 阻断解析器
 *
 * @return
 */
@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
    // paginationInterceptor.setOverflow(false);
    // 设置最大单页限制数量,默认 500 条,-1 不受限制
    // paginationInterceptor.setLimit(500);
    List<ISqlParser> sqlParserList = new ArrayList<>();
    // 攻击 SQL 阻断解析器、加入解析链
    sqlParserList.add(new BlockAttackSqlParser());
    paginationInterceptor.setSqlParserList(sqlParserList);
    return paginationInterceptor;
}
Also used : ISqlParser(com.baomidou.mybatisplus.core.parser.ISqlParser) ArrayList(java.util.ArrayList) BlockAttackSqlParser(com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 15 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project jshERP by jishenghua.

the class TenantConfig method paginationInterceptor.

@Bean
public PaginationInterceptor paginationInterceptor(HttpServletRequest request) {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    List<ISqlParser> sqlParserList = new ArrayList<>();
    TenantSqlParser tenantSqlParser = new TenantSqlParser();
    tenantSqlParser.setTenantHandler(new TenantHandler() {

        @Override
        public Expression getTenantId() {
            String token = request.getHeader("X-Access-Token");
            Long tenantId = Tools.getTenantIdByToken(token);
            if (tenantId != 0L) {
                return new LongValue(tenantId);
            } else {
                // 超管
                return null;
            }
        }

        @Override
        public String getTenantIdColumn() {
            return "tenant_id";
        }

        @Override
        public boolean doTableFilter(String tableName) {
            // 获取开启状态
            Boolean res = true;
            String token = request.getHeader("X-Access-Token");
            Long tenantId = Tools.getTenantIdByToken(token);
            if (tenantId != 0L) {
                // 这里可以判断是否过滤表
                if ("jsh_material_property".equals(tableName) || "jsh_sequence".equals(tableName) || "jsh_user_business".equals(tableName) || "jsh_function".equals(tableName) || "jsh_platform_config".equals(tableName) || "jsh_tenant".equals(tableName)) {
                    res = true;
                } else {
                    res = false;
                }
            }
            return res;
        }
    });
    sqlParserList.add(tenantSqlParser);
    paginationInterceptor.setSqlParserList(sqlParserList);
    paginationInterceptor.setSqlParserFilter(new ISqlParserFilter() {

        @Override
        public boolean doFilter(MetaObject metaObject) {
            MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);
            // 过滤自定义查询此时无租户信息约束出现
            if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) {
                return true;
            } else if ("com.jsh.erp.datasource.mappers.RoleMapperEx.getRoleWithoutTenant".equals(ms.getId())) {
                return true;
            } else if ("com.jsh.erp.datasource.mappers.LogMapperEx.insertLogWithUserId".equals(ms.getId())) {
                return true;
            }
            return false;
        }
    });
    return paginationInterceptor;
}
Also used : TenantHandler(com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler) MetaObject(org.apache.ibatis.reflection.MetaObject) ArrayList(java.util.ArrayList) ISqlParserFilter(com.baomidou.mybatisplus.core.parser.ISqlParserFilter) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) TenantSqlParser(com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser) ISqlParser(com.baomidou.mybatisplus.core.parser.ISqlParser) Expression(net.sf.jsqlparser.expression.Expression) LongValue(net.sf.jsqlparser.expression.LongValue) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Bean(org.springframework.context.annotation.Bean)

Aggregations

PaginationInterceptor (com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)19 Bean (org.springframework.context.annotation.Bean)16 ISqlParser (com.baomidou.mybatisplus.core.parser.ISqlParser)5 JsqlParserCountOptimize (com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize)5 ArrayList (java.util.ArrayList)5 MybatisSqlSessionFactoryBean (com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean)4 TenantHandler (com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler)3 TenantSqlParser (com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser)3 Expression (net.sf.jsqlparser.expression.Expression)3 LongValue (net.sf.jsqlparser.expression.LongValue)3 ISqlParserFilter (com.baomidou.mybatisplus.core.parser.ISqlParserFilter)2 BlockAttackSqlParser (com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser)2 MappedStatement (org.apache.ibatis.mapping.MappedStatement)2 MetaObject (org.apache.ibatis.reflection.MetaObject)2 MybatisConfiguration (com.baomidou.mybatisplus.core.MybatisConfiguration)1 DataSource (javax.sql.DataSource)1 Environment (org.apache.ibatis.mapping.Environment)1 Interceptor (org.apache.ibatis.plugin.Interceptor)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)1