網(wǎng)站首頁 編程語言 正文
開發(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
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-06-06 PowerShell yarn : 無法加載文件 C:\Users\Admin\AppData\Ro
- 2023-11-20 python實(shí)現(xiàn)ssh傳遞文件
- 2022-02-02 Maven命令安裝本地jar包到本地倉庫
- 2022-10-11 C++函數(shù)對象Functor與匿名函數(shù)對象Lambda表達(dá)式詳解_C 語言
- 2023-07-04 ES聚合查詢+條件搜索的實(shí)現(xiàn)
- 2022-11-25 詳解C++中類的六大默認(rèn)成員函數(shù)_C 語言
- 2022-07-03 golang defer,func()閉包,panic ,recover,contex
- 2024-01-06 RocketMQ死信消息解決方案
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支