How to let mybatis plus help us set up pagination and extract annotations

1. Write a configuration class

  • @ConfigurationIndicate it is a configuration class, spring will scan and load
  • @EnableTransactionManagementHere to indicate that the transaction annotation is turned on
  • @MapperScan("")The mapper that needs to be scanned is also indicated here
  • In this case, there is no need to indicate these annotations in the main startup class
@Configuration
@EnableTransactionManagement // 开启事务注解
@MapperScan("")
public class MybatisConfig {
    
    
    @Bean
    public PaginationInterceptor paginationInterceptor() {
    
    
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
         paginationInterceptor.setOverflow(true);
        // 设置最大单页限制数量,默认 500 条,-1 不受限制
         paginationInterceptor.setLimit(1000);
        // 开启 count 的 join 优化,只针对部分 left join
        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
        return paginationInterceptor;
    }
}

2. Related configuration

  • mybatis-plus:Configuration in the configuration file
  • mapper-locations:path
  • global-config.db-config.id-typeSelf-increment mode of database
mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  global-config:
    db-config:
      id-type: auto

3. To be updated

Guess you like

Origin blog.csdn.net/JISOOLUO/article/details/105578210