知识点:使用pagehelper实现分页功能

参考资料github上:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md

(1)不是maven项目,则需要下载引用pagehelper和jsqlparser两个jar包

http://repo1.maven.org/maven2/com/github/pagehelper/pagehelper/

http://repo1.maven.org/maven2/com/github/jsqlparser/jsqlparser/0.9.5/

maven项目只需,直接在pom.xml中引入依赖

<dependency>

<groupId>com.github.pagehelper</groupId>

<artifactId>pagehelper</artifactId>

<version>最新版本</version>

</dependency>

(2)在mybatis配置文件mybatis-config.xml中配置拦截器插件

<plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>

(3)在代码中使用分页功能

例如:1.查询所有数据,然后分页

Page<Object> page=PageHelper.startPage(4, 1);//4为第4页,1为每页的页数

注意:紧跟着的第一个select方法会被分页
            EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);//查询所有数据

2.需要连续显示多少页

);
            System.out.println("当前页码"+info.getPageNum());
            System.out.println("总记录数"+info.getTotal());
            System.out.println("每页记录数"+info.getPageSize());
            System.out.println("总页码"+page.getPages());
            
            System.out.println("连续显示的页码");
            int[] nums=info.getNavigatepageNums();
            for (int i : nums) {
                System.out.println(i);
            }

效果:

源码:https://github.com/shuaishuaihand/pagehelper.git

pagehelper的使用的更多相关文章

  1. PageHelper简单实用

    mybatis-config.xml配置如下: <!-- 分页插件 --> <plugins> <plugin interceptor="com.github. ...

  2. springboot使用之二:整合mybatis(xml方式)并添加PageHelper插件

    整合mybatis实在前面项目的基础上进行的,前面项目具体整合请参照springboot使用之一. 一.整合mybatis 整合mybatis的时候可以从mybatis官网下载mybatis官网整合的 ...

  3. 理解 Mybatis的分页插件 PageHelper

    Mybatis + SpringMVC + Maven实现分页查询 (推荐采用的插件是PageHelper) 先看一下之前的这篇博客,这里推荐了 Mybatis 的分页方法. 按照上面的方法设置后,确 ...

  4. Spring + Mybatis 使用 PageHelper 插件分页

    原文:http://www.cnblogs.com/yucongblog/p/5330886.html 先增加maven依赖: <dependency> <groupId>co ...

  5. Mybatis的分页插件PageHelper

    Mybatis的分页插件PageHelper 项目地址:http://git.oschina.net/free/Mybatis_PageHelper  文档地址:http://git.oschina. ...

  6. mybatis分页插件PageHelper的使用(转)

    Mybatis 的分页插件PageHelper-4.1.1的使用 Mybatis 的分页插件 PageHelper 项目地址:http://git.oschina.net/free/Mybatis_P ...

  7. MyBatis学习总结_17_Mybatis分页插件PageHelper

    如果你也在用Mybatis,建议尝试该分页插件,这一定是最方便使用的分页插件. 分页插件支持任何复杂的单表.多表分页,部分特殊情况请看重要提示. 想要使用分页插件?请看如何使用分页插件. 物理分页 该 ...

  8. Spring集成PageHelper的简单用法

    1.Maven依赖,注意使用PageHelper时的版本必须与Mybatis版本对应 <!-- 添加Mybatis依赖 --> <dependency> <groupId ...

  9. Mybatis分页插件PageHelper正确的用法(网上有2篇不够科学的文章)

    今天下午在Mybatis项目中.实现分页.由于我是后加入项目中的,Leader用的是PageHelper这个组件.可是我在实际使用的过程中遇到了2个大问题. 1.p=2#comments" ...

  10. maven+springmvc+easyui+fastjson+pagehelper

    1.maven配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

随机推荐

  1. ubuntu重新设置登陆界面|切换gdm kdm lightdm

    方法: $ sudo dpkg-reconfigure gdm 然后会出一个让你进行选择的提示,根据需要切换即可

  2. MapReduce的核心编程思想

    1.MapReduce的核心编程思想 2.yarn集群工作机制 3.maptask并行度与决定机制 4.maptask工作机制 5.MapReduce整体流程 6.shuffle机制 7.yarn架构

  3. shell awk实战

    一.文本处理 1.按行提取关键字频次(如取第5列) awk 'BEGIN{FS="|"} {a[$5]+=1;} END {for(i in a) print i ":& ...

  4. 入木三分学网络第一篇--VRRP协议详解第一篇(转)

    因为keepalived使用了VRRP协议,所有有必要熟悉一下. 虚拟路由冗余协议(Virtual Router Redundancy Protocol,简称VRRP)是解决局域网中配置静态网关时,静 ...

  5. LInux进程虚拟地址空间的管理

    2017-04-07 脱离物理内存的管理,今天咱们来聊聊进程虚拟内存的管理.因为进程直接分配和使用的都是虚拟内存,而物理内存则是有系统“按需”分配给进程,在进程看来,只知道虚拟内存的存在! 前言: 关 ...

  6. Flask之session相关

    Flask的session简介 除请求对象之外,还有一个 session 对象.它允许你在不同请求间存储特定用户的信息.它是在 Cookies 的基础上实现的,并且对 Cookies 进行密钥签名要使 ...

  7. Ubentu下安装Docker

    具体可以查看Docker官网,我是在服务器上面操作 1,sudo apt-get install -y apt-transport-https ca-certificates curl softwar ...

  8. sql server中使用xp_cmdshell

    关键词:sql server开启高级配置,使用Bat,cmdshell 1.sql server中使用xp_cmdshell --允许配置高级选项 GO RECONFIGURE GO . --开启xp ...

  9. abap 中modify 的使用

    1.modify table itab from wa Transporting f1 f2 ... 表示表itab中符合工作区wa 中关键字的一条数据的 f1 f2字段会被wa中对应的字段值更新. ...

  10. Check back what the kd 6 for more info

    Representing a shout-to his fans in China, the What the KD 6 may be the product of NIKEiD's Player E ...