日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

在MyBatisPlus中添加分頁插件

作者:m0_59259076 更新時間: 2023-10-11 編程語言

開發(fā)過程中,數(shù)據(jù)量大的時候,查詢效率會有所下降,這時,我們往往會使用分頁。

具體操作入下:

1、添加分頁插件:

package com.zhang.config;


import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;


@EnableTransactionManagement
@Configuration
@MapperScan("com.zhang.mapper")
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        // 1、創(chuàng)建分頁插件
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        //   2、添加分頁插件
        paginationInterceptor.setLimit(500);
        return paginationInterceptor;
    }
}

2、編寫接口:

    @GetMapping(value = "/testPages")
    public R<?> test(@RequestParam("pageNo") Integer pageNo
            , @RequestParam("pageSize") Integer pageSize) {
//        1、分頁條件
        Page<Animal> page = new Page<>(pageNo, pageSize);
//        2、分頁排序
        page.addOrder(OrderItem.asc("age"));

        IPage<Animal> pages = animalService.page(page);
        return R.ok(pages);
    }

3、測試分頁效果:

如:

{
	"code": 0,
	"data": {
		"records": [
			{
				"id": "1775e2db7fb5e0d9b8e98d4137f58b91",
				"name": "狗毛",
				"age": 2,
				"delFlag": "正常",
				"hobby": "骨",
				"createTime": "2023-09-30T04:10:22.000+00:00",
				"updateTime": "2022-01-30T08:55:56.000+00:00",
				"relation": null
			},
			{
				"id": "320f4e82f56d66cb8d8ab2c991f9526c",
				"name": "狗哥",
				"age": 2,
				"delFlag": "正常",
				"hobby": "骨頭",
				"createTime": "2022-02-23T06:24:22.000+00:00",
				"updateTime": null,
				"relation": null
			}
		],
		"total": 9,
		"size": 2,
		"current": 1,
		"orders": [
			{
				"column": "age",
				"asc": true
			}
		],
		"searchCount": true,
		"pages": 5
	},
	"msg": "執(zhí)行成功"
}

原文鏈接:https://blog.csdn.net/m0_59259076/article/details/133439417

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新