Search in sources :

Example 16 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project kykms 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 17 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project tutorials-java by Artister.

the class MybatisPlusConfig method paginationInterceptor.

/**
 * 多租户属于 SQL 解析部分,依赖 MP 分页插件
 */
@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    /*
         * 【测试多租户】 SQL 解析处理拦截器<br>
         * 这里固定写成住户 1 实际情况你可以从cookie读取,因此数据看不到 【 麻花藤 】 这条记录( 注意观察 SQL )<br>
         */
    List<ISqlParser> sqlParserList = new ArrayList<>();
    TenantSqlParser tenantSqlParser = new TenantSqlParser();
    tenantSqlParser.setTenantHandler(new TenantHandler() {

        @Override
        public Expression getTenantId() {
            return new LongValue(1L);
        }

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

        @Override
        public boolean doTableFilter(String tableName) {
            /*if ("user".equals(tableName)) {
                    return true;
                }*/
            return false;
        }
    });
    sqlParserList.add(tenantSqlParser);
    paginationInterceptor.setSqlParserList(sqlParserList);
    // });
    return paginationInterceptor;
}
Also used : TenantHandler(com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler) ISqlParser(com.baomidou.mybatisplus.core.parser.ISqlParser) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) LongValue(net.sf.jsqlparser.expression.LongValue) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) TenantSqlParser(com.baomidou.mybatisplus.extension.plugins.tenant.TenantSqlParser) Bean(org.springframework.context.annotation.Bean)

Example 18 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project dolphinscheduler by apache.

the class ConnectionFactory method getSqlSessionFactory.

/**
 * * get sql session factory
 *
 * @return sqlSessionFactory
 * @throws Exception sqlSessionFactory exception
 */
private SqlSessionFactory getSqlSessionFactory() throws Exception {
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, getDataSource());
    MybatisConfiguration configuration = new MybatisConfiguration();
    configuration.setEnvironment(environment);
    configuration.setLazyLoadingEnabled(true);
    configuration.addMappers("org.apache.dolphinscheduler.dao.mapper");
    configuration.addInterceptor(new PaginationInterceptor());
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    sqlSessionFactoryBean.setConfiguration(configuration);
    sqlSessionFactoryBean.setDataSource(getDataSource());
    sqlSessionFactoryBean.setTypeEnumsPackage("org.apache.dolphinscheduler.*.enums");
    sqlSessionFactory = sqlSessionFactoryBean.getObject();
    return sqlSessionFactory;
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) MybatisConfiguration(com.baomidou.mybatisplus.core.MybatisConfiguration) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor)

Example 19 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project alarm-bot by zzq0324.

the class MybatisPlusAutoConfiguration method paginationInterceptor.

@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
    // paginationInterceptor.setOverflow(false);
    // 设置最大单页限制数量,默认 500 条,-1 不受限制
    // paginationInterceptor.setLimit(500);
    // 开启 count 的 join 优化,只针对部分 left join
    paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
    return paginationInterceptor;
}
Also used : JsqlParserCountOptimize(com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) 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