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

JavaScript tips to help you improve your coding skills

Table of contents 1. Filter unique values 2. Shor...

Introduction to the usage of exists and except in SQL Server

Table of contents 1. exists 1.1 Description 1.2 E...

CSS and JS to achieve romantic meteor shower animation

1. Rendering 2. Source code HTML < body > &...

How to use CSS to center a box horizontally and vertically (8 methods)

Original code: center.html : <!DOCTYPE html>...

Common browser compatibility issues (summary)

Browser compatibility is nothing more than style ...

JavaScript to achieve Taobao product image switching effect

JavaScript clothing album switching effect (simil...

Native js to achieve star twinkling effect

This article example shares the specific code of ...

XHTML Getting Started Tutorial: What is XHTML?

What is HTML? To put it simply: HTML is used to m...

Detailed steps and problem solving methods for installing MySQL 8.0.19 on Linux

I recently bought a Tencent Cloud server and buil...

WeChat Mini Program video barrage position random

This article shares the specific code for randomi...

ul list tag design web page multi-column layout

I suddenly thought of this method when I was writi...

MySQL master-slave replication principle and points to note

Written in front I have been writing a special to...

Using JS to implement a small game of aircraft war

This article example shares the specific code of ...

Detailed explanation of setting Context Path in Web application

URL: http://hostname.com/contextPath/servletPath/...

Summary of MySQL development standards and usage skills

1. Naming conventions 1. Database names, table na...