知识点:使用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. UVA10870—Recurrences(简单矩阵快速幂)

    题目链接:https://vjudge.net/problem/UVA-10870 题目意思: 给出a1,a2,a3,a4,a5………………ad,然后算下面这个递推式子,简单的矩阵快速幂,裸题,但是第 ...

  2. c#使用FastReports打印

    private void btnprint_Click(object sender, EventArgs e) { //报表路径 string path = Application.StartupPa ...

  3. 服务端使用Zookeeper注册服务地址,客户端从Zookeeper获取可用的服务地址。

    一个轻量级分布式RPC框架--NettyRpc - 阿凡卢 - 博客园 http://www.cnblogs.com/luxiaoxun/p/5272384.html 这个RPC框架使用的一些技术所解 ...

  4. jsp->jar

    (2)新建 WEB-INF目录 (3)在 WEB-INF/web.xml 中输入如下内容 <web-app xmlns="http://java.sun.com/xml/ns/j2ee ...

  5. PXE,ipmi,bare metal

    IPMI(Intelligent Platform Management Interface)是一个智能平台管理接口. 用户可以利用IPMI 监视服务器等设备的物理特征,如各部件的温度.电压.风扇工作 ...

  6. [Shell] 简单的自动检查ssh代理是否正常的脚本

    As Follows: #!/bin/bash RESPONSE=`curl -s --socks5 www.123cha.com` -eq $? ] then echo SUCCESS else e ...

  7. mysql主从同步出现异常语句跳过错误处理

    1.跳过操作: mysql>slave stop; mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 跳过一个事务 mysql>slave st ...

  8. Vi 的常用命令

    1. vi 的三种工作模式 命令模式 打开文件首先进入命令模式, 是使用 vi 的入口; 通过命令对文件进行常规的编辑操作, 例如: 定位,翻页,复制,粘贴,删除等; 末行模式 执行保存,退出等操作, ...

  9. 部署knight项目

    发布CRM你将使用以下软件 nginx uWSGI CentOS7 CRM项目文件 virtualenv supervisor WSGI.uWSGI python web服务器开发使用WSGI协议(W ...

  10. 利用ssh的私钥登录Linux server

    [https://blog.csdn.net/hello0370/article/details/41650513] 1.创建一个private key的文件,我使用vim编辑器,创建vi my_pr ...