In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how Mybatis Plus uses paging, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will gain something after reading this Mybatis Plus paging article, let's take a look at it.
Mybatis-Plus (MP for short) is an enhancement tool for Mybatis, which is only enhanced but not changed on the basis of Mybatis. It is created to simplify development and improve efficiency.
1. Write a Mybatis-plus configuration class:
Paging is achieved through the interceptor
@ Configurationpublic class MybatisConfig {@ Bean public MybatisPlusInterceptor mybatisPlusInterceptor () {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor (); interceptor.addInnerInterceptor (new PaginationInnerInterceptor (DbType.MYSQL)); return interceptor;}}
Copy it on the official website, but you need to change the database to your use. Here I use mysql
two。 Write interface test
It's simple
@ GetMapping ("/ test") public Response test () {Page producePage = new Page (1Power1); Page page = produceService.page (producePage); System.out.println (producePage = = page); List records = page.getRecords (); for (Produce record: records) {System.out.println (record);} return new Response (records, ResultEnum.SUCCESS);}
By default, the total number of entries will be queried. All of them have get and set methods. You can set them according to your own needs (click on the Page class to see)
3. Be careful
The page object we passed in is the same as the page object returned by the query
4. If you still have query conditions
For example, we only query paging queries with id and price,id less than 5.
1.Lambda expression @ GetMapping ("/ test") public Response test () {Page producePage = new Page (1Power2); Page page = new LambdaQueryChainWrapper (produceService.getBaseMapper ()) .select (Produce::getPid,Produce::getPrice) .lt (Produce::getPid,5) .page (producePage); return new Response (page.getRecords (), ResultEnum.SUCCESS);}
two。 Ordinary query @ GetMapping ("/ test") public Response test () {Page producePage = new Page (1d2); QueryWrapper queryWrapper = new QueryWrapper (); queryWrapper.select ("pid", "price"); queryWrapper.lt ("pid", 5); Page page = produceService.page (producePage, queryWrapper); return new Response (page.getRecords (), ResultEnum.SUCCESS);}
This is the end of the article on "how to use paging in Mybatis Plus". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use Mybatis Plus paging". If you want to learn more, you are 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.