Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of paging query in MyBatis-Plus

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "what are the methods of MyBatis-Plus paging query", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the methods of MyBatis-Plus paging query" can help you solve your doubts? let's follow the editor's way of thinking to learn new knowledge.

Methods:

Use the selectPage () method

The first parameter is to pass in the paging method (pass in the current page and how many pieces of data are currently displayed)

The second parameter is to pass in the query condition (you can pass null if the query is all).

Premise:

The data in the table is:

The first way is: / / paging query Page employees = employeeMapper.selectPage (new Page (3,2), null); System.out.println ("data is:" + employees.getRecords ()); System.out.println ("Total: + employees.getTotal () +", total number of pages: "+ employees.getPages ()); System.out.println (" current page: "+ employees.getCurrent () +", per page limit: "+ employees.getSize ()

The result is:

Shows all the data, there are no totals, and there is no paging effect.

The second way: / / paging query Page employees = employeeMapper.selectPage (new Page (3,2), null); Integer count = employeeMapper.selectCount (null); employees.setTotal (count); System.out.println ("data is:" + employees.getRecords ()); System.out.println ("Total:" + employees.getTotal () + ", total pages:" + employees.getPages ()) System.out.println ("current page is:" + employees.getCurrent () + ", per page limit:" + employees.getSize ())

The result is:

Although there is a total number and total number of pages, there is still no effect of paging.

The third way: / / paging query Page employees = employeeMapper.selectPage (new Page (3,2), null); System.out.println ("data:" + employees.getRecords ()); System.out.println ("Total: + employees.getTotal () +", total number of pages: "+ employees.getPages ()); System.out.println (" current page: "+ employees.getCurrent () +", per page limit: "+ employees.getSize ())"

Add Mybatis-Plus plug-in

@ Configurationpublic class MyBatisPlusConfig {@ Bean public PaginationInterceptor paginationInterceptor () {PaginationInterceptor page = new PaginationInterceptor (); return page;}}

Results:

After reading this, the article "what are the methods of MyBatis-Plus paging query" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report