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 uses and precautions of Mybatis-Plus pagination

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "what is the use of Mybatis-Plus pages and matters needing attention". The editor shows you the operation process through actual cases, the operation method is simple and fast, and it is practical. I hope this article "what is the use of Mybatis-Plus pages and matters needing attention" can help you solve the problem.

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 content about "what are the uses and precautions of Mybatis-Plus pagination". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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