After mybatis-plus paging parameters are passed in, the sql where condition does not have limit paging information operation

After mybatis-plus paging parameters are passed in, the sql where condition does not have limit paging information operation

I spent almost two hours trying various methods. Later I thought that the amount of data after filtering by where did not reach the default number of one page, so I simply did not display the limit information in where. After trying it, it was indeed the case. . . The author really made the program smart enough, but this intelligence also made me waste two hours in vain. . . Or maybe I am just too stupid...

But the strange thing is that if I don't set the QueryWrapper parameter, the paging limit after where can be seen again. I can't figure out what the author is thinking. . .

See the code for details:

@Override
 public PageUtils queryPage(Map<String, Object> params) {
 
  IPage<OrderEntity> page = this.page(
    new Query<OrderEntity>().getPage(params),
    new QueryWrapper<OrderEntity>().eq(!UtilString.isNull(params.get("user_id"))
      ,"user_id", params.get("user_id"))
  );
 
  return new PageUtils(page);
 }

The purpose of recording is to hope that friends who encounter this special situation like me can quickly bypass this corner, time is precious. Good night^.^

Finally, I attach the official document. I hope you can read the document more systematically.

https://mp.baomidou.com/guide/dynamic-datasource.html

Supplementary knowledge: Record the pit of limit failure of mybatisplus paging method generated by reverse engineering

Because before I solved the problem, I also searched for solutions on the Internet and the official website, but there was no solution, so this is why I wrote this article, hoping

Students who come after you can avoid detours when developing

Controller layer

 @RequestMapping("/list")
 public R list(@RequestParam Map<String, Object> params){
  PageUtils page = categoryService.queryPage(params);
  return R.ok().put("page", page);
 }

The parameters passed are as shown in the figure

Server interface

public interface CategoryService extends IService<CategoryEntity> {
 
 PageUtils queryPage(Map<String, Object> params);
 }

Problem and solution (this is the solution on the Internet and it has not been solved...)

However, when querying, the paging does not take effect, and the query result is all the data in the table. If the pom is correct, check whether the paging interceptor is injected into spring.

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
@Configuration
public class mybatisPlusConfig {
 @Bean
 public PaginationInterceptor paginationInterceptor(){
  return new PaginationInterceptor();
 }
}

The above is the solution I found on the Internet. I copied it into the project and found that the method is outdated and does not work.

Later I found that the problem was that my mybatisplus version was too high, so it was not supported

This is the version I referenced in Maven

Then search the interceptor method on the Internet

The problem is solved by using a new paging method

The key to the problem is how to find the problem fundamentally. For me, I reflected on the method of finding the problem, so that I would not waste 1 or 2 hours today without finding it. I would go to the official documentation first.

Check out the official example code! ! ! ! ! !

The following is the reverse engineering I found on gitee

Because the project schedule is very tight, and I have a headache looking at my colleague's old framework code, wouldn't it be great to choose reverse engineering and build a lightweight framework by myself?

Because the project uses springcloud microservices, I am responsible for a system so I can do whatever I want.

The reverse engineering I use here is the renren-generator framework on gitee

There is no interceptor for the paging method in the code he generated. I found that the method on the official website is also outdated, which is very pitfall.

The above article about mybatis-plus paging and sql where condition without limit paging information operation is all I want to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Mybatis where tag usage
  • Mybatis plus where to add brackets
  • Mybatisplus where QueryWrapper plus brackets nested query method
  • Solve the problem that if in mybatis where-if cannot recognize uppercase AND, OR
  • Mybatis dynamic SQL if, choose, where, set, trim, foreach tag example detailed explanation
  • Summary of the use of Mybatis where tag

<<:  Enable OCSP to improve https certificate verification efficiency and solve the problem of slow access to Let's Encrypt SSL certificates

>>:  Example of Html shielding right-click menu and left-click typing function

Recommend

Best Practices for Implementing Simple Jira Projects with React+TS

A set of projects for training react+ts Although ...

Detailed explanation of HTML page header code example

Knowledge point 1: Set the base URL of the web pa...

Deeply understand how nginx achieves high performance and scalability

The overall architecture of NGINX is characterize...

MySQL case when usage example analysis

First we create the database table: CREATE TABLE ...

Tutorial on deploying springboot package in linux environment using docker

Because springboot has a built-in tomcat server, ...

Vue implements a simple timer component

When doing a project, it is inevitable to encount...

...

Example of implementing translation effect (transfrom: translate) with CSS3

We use the translate parameter to achieve movemen...

HTML tutorial, easy to learn HTML language (2)

*******************Introduction to HTML language (...

Vue3 encapsulates its own paging component

This article example shares the specific code of ...

Detailed explanation of MySQL's FreeList mechanism

1. Introduction After MySQL is started, BufferPoo...

Detailed explanation of the simple use of MySQL query cache

Table of contents 1. Implementation process of qu...