A, MybatisPlusInterceptor
Starting from MybatisPlus 3.4.0, we don’t use the PaginationInterceptor of the old version, but use the MybatisPlusInterceptor.
MybatisPlusInterceptor is a chain of interceptors that implement InnerInterceptor, also known as a collection. The following interceptors can be included
- Automatic paging: PaginationInnerInterceptor (most common)
- Multi-tenancy: TenantLineInnerInterceptor
- Dynamic table name: DynamicTableNameInnerInterceptor
- Optimistic locking: OptimisticLockerInnerInterceptor
- SQL performance specification: IllegalSQLInnerInterceptor
- To prevent a full table update and delete: BlockAttackInnerInterceptor
(Before Mybatis Plus 3.4.0)
@Configuration @MapperScan(basePackages = {"com.zimug.**.mapper"}) public class MybatisPlusConfig { @Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); / / set the request page after page is greater than the maximum operation, true transferred back to the home page, the default false false continue to request / / paginationInterceptor setOverflow (false); / / set the biggest single page limit an amount, the default 500-1 is not restricted. / / paginationInterceptor setLimit (500); / / open the count of the join optimization, only part of the left join paginationInterceptor. SetCountSqlParser (new JsqlParserCountOptimize (true)); return paginationInterceptor; }}Copy the code
(Mybatis Plus 3.4.0 and later versions)
The new paging plugin follows the rules of Mybatis and requires MybatisConfiguration#useDeprecatedExecutor = false to avoid caching problems
@Configuration @MapperScan(basePackages = {"com.zimug.**.mapper"}) public class MybatisPlusConfig { /** * The new paging plugin, which follows the rules of Mybatis, needs to set MybatisConfiguration#useDeprecatedExecutor = false to avoid caching problems (this property will be removed when the old plugin is removed) */ @bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); / / to add paging Mybatis filter chain blocker interceptor. AddInnerInterceptor (new PaginationInnerInterceptor (DbType. MYSQL)); // You can also add a return interceptor; } @Bean public ConfigurationCustomizer configurationCustomizer() { return configuration -> configuration.setUseDeprecatedExecutor(false); }}Copy the code
Four, the use of paging query
There is no change in the use of paging queries, which remains the same as the previous version of Mybatis. Here’s a quick example
Page<SysUserOrg> page = new Page<> (pageNum,pageSize); // Select pageSize as the first parameter of Mybatis or Mybatis Plus. Can complete the paging query return mySystemMapper. SelectUser (page, other parameters);Copy the code
Welcome to my blog, where there are many fine collections
- This article is reprinted with a credit (must be accompanied by a link, not only the text) : Antetokounmpo blog.
Feel helpful to you, help me like, share! Your support is my inexhaustible creative power! . In addition, the author recently a period of time output as follows boutique content, looking forward to your attention.
- Spring Boot2.0 by Hand
- Spring Security- JWT-OAUTH2
- RBAC Authority Management System for Actual Combat Front-end and Back-end Separation
- “Actual SpringCloud Micro-service from Bronze to King”
- VUE Series