Search in sources :

Example 1 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project springboot-learning by lyb-geek.

the class MyBatisPlusTenantConfig 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));
    if (myBatisPlusTenantProperties.isEnabled()) {
        tenantHandler(paginationInterceptor);
    }
    return paginationInterceptor;
}
Also used : JsqlParserCountOptimize(com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project JBM by numen06.

the class MybatisPlusConfig method paginationInterceptor.

/**
 * 分页拦截器
 *
 * @return
 */
@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    paginationInterceptor.setDialectType("mysql");
    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;
    // }
    // });
    paginationInterceptor.setSqlParserList(sqlParserList);
    // });
    return paginationInterceptor;
}
Also used : ISqlParser(com.baomidou.mybatisplus.core.parser.ISqlParser) ArrayList(java.util.ArrayList) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 3 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project study-by-myself by Howinfun.

the class MybatisPlusConfig method paginationInterceptor.

@Bean
public PaginationInterceptor paginationInterceptor() {
    final PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    paginationInterceptor.setLimit(-1);
    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)

Example 4 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project poseidon by muggle0.

the class MybatisPlusConfig method createSqlSessionFactoryBean.

@Bean(name = "sqlSessionFactory")
public SqlSessionFactory createSqlSessionFactoryBean(@Qualifier(value = "globalConfig") GlobalConfig configuration) throws Exception {
    log.info("初始化SqlSessionFactory");
    MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);
    Interceptor[] interceptor = { new PaginationInterceptor() };
    sqlSessionFactoryBean.setPlugins(interceptor);
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    // sqlSessionFactoryBean.setTypeHandlers(new TypeHandler[]{new MybatisDataHandler()});
    try {
        sqlSessionFactoryBean.setGlobalConfig(configuration);
        sqlSessionFactoryBean.setMapperLocations(resolver.getResources(mapperLocations));
        sqlSessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage);
        return sqlSessionFactoryBean.getObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sqlSessionFactoryBean.getObject();
}
Also used : MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) Interceptor(org.apache.ibatis.plugin.Interceptor) PaginationInterceptor(com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor) MybatisSqlSessionFactoryBean(com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with PaginationInterceptor

use of com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor in project mall-learning by macrozheng.

the class MyBatisConfig method paginationInterceptor.

@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    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