首页 > 其他分享 >分页PageInterceptor

分页PageInterceptor

时间:2023-08-31 21:11:25浏览次数:34  
标签:count 分页 countMsId PageInterceptor countMs ms pagehelper

依赖引入

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>xx.xx.xx</version>
</dependency>

编码

PageHelper.startPage()在查询前执行,设置Page放入ThreadLocal中

  /com/github/pagehelper/page/PageMethod.java:147

PageInterceptor拦截请求,自动添加limit & offset

  /com/github/pagehelper/util/ExecutorUtil.java:166

/com/github/pagehelper/PageInterceptor.java:140,count计数
private Long count(Executor executor, MappedStatement ms, Object parameter,
                       RowBounds rowBounds, ResultHandler resultHandler,
                       BoundSql boundSql) throws SQLException {
        String countMsId = countMsIdGen.genCountMsId(ms, parameter, boundSql, countSuffix);
        Long count;
        //先判断是否存在手写的 count 查询
        MappedStatement countMs = ExecutorUtil.getExistedMappedStatement(ms.getConfiguration(), countMsId);
        if (countMs != null) {
            count = ExecutorUtil.executeManualCount(executor, countMs, parameter, boundSql, resultHandler);
        } else {
            if (msCountMap != null) {
                countMs = msCountMap.get(countMsId);
            }
            //自动创建
            if (countMs == null) {
                //根据当前的 ms 创建一个返回值为 Long 类型的 ms
                countMs = MSUtils.newCountMappedStatement(ms, countMsId);
                if (msCountMap != null) {
                    msCountMap.put(countMsId, countMs);
                }
            }
            count = ExecutorUtil.executeAutoCount(this.dialect, executor, countMs, parameter, boundSql, rowBounds, resultHandler);
        }
        return count;
    }
@Bean
public PageInterceptor pageInterceptor(){
return new PageInterceptor();
}
@GetMapping("/geta")
private PageInfo<Demo> getA(@RequestParam String str) {
    PageHelper.startPage(1, 3);
    List<Demo> querydemo = demoBaseMapper.querydemo(str);
    PageInfo<Demo> pageInfo = new PageInfo<Demo>(querydemo);
    return pageInfo;
}
{
    "total": 2,
    "list": [
        {
            "id": 1,
            "name": "tom",
            "date": "2023-08-28T16:00:00.000+00:00"
        }
    ],
    "pageNum": 1,
    "pageSize": 3,
    "size": 2,
    "startRow": 1,
    "endRow": 2,
    "pages": 1,
    "prePage": 0,
    "nextPage": 0,
    "isFirstPage": true,
    "isLastPage": true,
    "hasPreviousPage": false,
    "hasNextPage": false,
    "navigatePages": 8,
    "navigatepageNums": [
        1
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 1
}

标签:count,分页,countMsId,PageInterceptor,countMs,ms,pagehelper
From: https://www.cnblogs.com/boomcc/p/17670423.html

相关文章

  • 关于分页查询数据重复的问题 (分页查看时数据库插入导致) 的一个解决办法
    既然是在我分页的过程中,插入了一条记录,导致我再查询下一页的时候,查出来上一页的记录,那么,我思考,我可不可以不去查询他新增的这一条记录。那么这样,就查询不到别人新增的这条记录了。那么需要的条件就出来了:数据库表要有创建时间的这么一个字段那么解决思路就出来了,首先是要前端进行......
  • thinkphp5 日期+group by + 分页paginate查询
    <?php//根据日期来统计所消耗的点数//模型的使用方法$result=$model->field("id,FROM_UNIXTIME(createtime,'%Y-%m-%d')as`createtime`,sum(price)ascount_price")->group("FROM_UNIXTIME(createtime,'%Y-%m-%d'),store......
  • mybatis plus 3.4以上分页无效问题,limit一直加不上,MybatisPlusInterceptor无效
    解决方案1、已注册@BeanpublicMybatisPlusInterceptormybatisPlusInterceptor(){MybatisPlusInterceptorinterceptor=newMybatisPlusInterceptor();PaginationInnerInterceptorpaginationInnerInterceptor=newPaginationInnerInterceptor(D......
  • 1.操作系统(基本分页存储管理的基本概念)
    1.操作系统(基本分页存储管理的基本概念)连续分配:为用户进程分配的必须是一个连续的内存空间。非连续分配:为用户进程分配的可以是一些分散的内存空间。1.思考:连续分配方式的缺点考虑支持多道程序的两种连续分配方式:1.固定分区分配:缺乏灵活性,会产生大量的内部碎片,内存......
  • django(Ajax、自定义分页器、form组件)
    一、Ajax1概述异步提交局部刷新例子:github注册动态获取用户名实时的跟后端确认并实时展示到前端(局部刷新)朝后端发送请求的方式1.浏览器地址栏直接输入url回车GET请求2.a标签href属性GET请求3.form表单GET......
  • DQL-分页查询
       页数就是里面的那个第几行......
  • phpcmsV9调用默认的分页样式
    //回复列表 publicfunctionganyanreply(){//点击后台-内容-留言管理,默认运行到这 $page=isset($_GET['page'])?intval($_GET['page']):1;//分页 $tablename=$this->db->db_tablepre.$MODEL[$modelid]['tablename'];// $this->db->......
  • 系统内存管理:虚拟内存、内存分段与分页、页表缓存TLB以及Linux内存管理
    虚拟内存虚拟内存是一种操作系统提供的机制,用于将每个进程分配的独立的虚拟地址空间映射到实际的物理内存地址空间上。通过使用虚拟内存,操作系统可以有效地解决多个应用程序直接操作物理内存可能引发的冲突问题。在使用虚拟内存的情况下,每个进程都有自己的独立的虚拟地址空间,它......
  • 史上最强.NET数据分页方法
    【前言】本文讲述的.NET数据分页方法为【史上最强】,已被多家大型科技公司实战采用& 也被圈内多家知名IT培训机构转载收藏。 【正文】支持.NetCore(2.0及以上)与.NetFramework(4.5及以上)可以部署在Docker,Windows,Linux,Mac。数据分页,几乎是任何应用系统的必备功......
  • 千万级数据深分页查询SQL性能优化实践 | 京东云技术团队
    一、系统介绍和问题描述如何在Mysql中实现上亿数据的遍历查询?先来介绍一下系统主角:关注系统,主要是维护京东用户和业务对象之前的关注关系;并对外提供各种关系查询,比如查询用户的关注商品或店铺列表,查询用户是否关注了某个商品或店铺等。但是最近接到了一个新需求,要求提供查询关注对......