知识点:使用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. python学习笔记(二)— 集合

    s = set()#建立空的集合 s2 = {'}#没有:的为集合,集合天生去重 s3 = {'} #集合是也是无序的 # s2.add('a')#添加值 # s2.remove('2')#删除值 # ...

  2. 隐藏Apache、nginx和PHP的版本号的配置方法

    最近提示说有漏洞,暴露apache.nginx和php的版本号.网上搜了下,整理的方法如下: 首先说apache 在http.conf文件里添加下面两行,默认是没有的 ServerSignature ...

  3. linux下非root用户的sudo问题

    linux下的root用户是个超级管理员,一般是不用这个用户登录进行操作的,但有时候需要root权限,又不想切换用户的话可以使用sudo命令.但是不是所有的用户都可以使用sudo命令的. 首先可能会遇 ...

  4. VMwareWorkstations中安装ubuntu,apt install报E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)

    ubuntu中apt安装软件python时报: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily un ...

  5. 【使用时发生的意外】HDFS 分布式写入问题 AlreadyBeingCreatedException

    进行追加文件时出现AlreadyBeingCreatedException错误 堆栈信息大致如下: org.apache.hadoop.ipc.RemoteException(org.apache.h ...

  6. 一.shell基础知识

    参考网站:http://billie66.github.io/TLCL/book/chap08.html 1.字符“*”--展开 [me@linuxbox ~]$ echo * Desktop Doc ...

  7. xpath草稿

    (一)日期和简介 date:2017/12/18 name:a标签href属性提取抛出异常list index out of range (二)问题详细说明: 以百度新闻页面为例: 1.node_li ...

  8. 008-mac下apache tomcat 测试授权

    一.下载 下载合适版本即可zip包 2.对bin下的*.sh授权 chmod 755 *.sh 3.80端口 https://blog.csdn.net/ilovesmj/article/detail ...

  9. 007-Shell test 命令,[],[[]]

    一.概述 test 命令用于检查某个条件是否成立,它可以进行数值.字符和文件三个方面的测试. 其中[]完全等价于test,只是写法不同.双中括号[[]]基本等价于[],它支持更多的条件表达式,还允许在 ...

  10. JS浮点计算问题

    问题 用js进行浮点数计算,结果可能会“超出预期”,大部分计算结果还是对的,但是我们可不想在计算这么严谨的事情上还有意外的惊喜.比如: 0.3 + 0.6 = 0.8999999999999999 0 ...