Changes of paging plug-in after mybatis plus version 3.4

Time:2022-1-3
Changes of paging plug-in after mybatis plus version 3.4

file

1、 Mybatisplusinterceptor

Starting with mybatis plus version 3.4.0, the old version of paginationinterceptor is no longer used, but mybatisplusinterceptor is used instead.

Mybatisplusinterceptor is a series of interceptor chains that implement innerinterceptor, which can also be understood as a collection. Some interceptors can be included as follows

  • Automatic paging: paginationinnerinterceptor (most commonly used)
  • Multi tenant: tenantlineinnerinterceptor
  • Dynamic table name: dynamictablenameinnerinterceptor
  • Optimistic lock: optimisticlockerinnerinterceptor
  • SQL performance specification: illegalsqlinnerinceptor
  • Prevent full table update and deletion: blockattackinnerinterceptor

2、 Configuration method of old pagination plug-in (before mybatis plus version 3.4.0)

@Configuration
@MapperScan(basePackages = {"com.zimug.**.mapper"})
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        //After setting the requested page to be larger than the maximum page, true will be called back to the home page, false will continue to request, and the default is false
        // paginationInterceptor.setOverflow(false);
        //Set the maximum number of single page restrictions, 500 by default, - 1 unlimited
        // paginationInterceptor.setLimit(500);
        //Turn on the join optimization of count, only for some left joins
        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
        return paginationInterceptor;
    }
}

3、 New paging plug-in configuration method (mybatis plus version 3.4.0 and later)

The new paging plug-in follows the rules of mybatis. Mybatisconfiguration#usedeprecatedexecutor = false should be set to avoid cache problems

@Configuration
@MapperScan(basePackages = {"com.zimug.**.mapper"})
public class MybatisPlusConfig {

  /**
   *The new paging plug-in follows the rules of mybatis. Mybatisconfiguration#usedeprecatedexecutor = false should be set to avoid cache problems (this attribute will be removed after the old plug-in is removed)
   */
  @Bean
  public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    //Add a paging interceptor to the mybatis filter chain
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    //You can also add I his interceptors
    return interceptor;
  }

  @Bean
  public ConfigurationCustomizer configurationCustomizer() {
    return configuration -> configuration.setUseDeprecatedExecutor(false);
  }
}

4、 Usage of paging query

There is no change in the usage of paging query, which is still consistent with the previous version of mybatis。 Here is a simple example

Page<SysUserOrg> page = new Page<> (pageNum,pageSize);   // Query pagenum page, PageSize data of each page
//Pass the paging parameter page as the first parameter of mybatis or mybatis plus into the persistence layer function to complete the paging query
return mySystemMapper. Selectuser (page, other parameters);

Welcome to my blog. There are many collections of boutiques in it

  • Reprint of this article shall indicate the source (it must be connected, not just text):Letter brother blog

If you think it’s helpful to you, please give me some praise and share! Your inexhaustible support for my creation!。 In addition, the author recently output the following high-quality content, looking forward to your attention.