第一步:引入pageHelper的jar包。

链接:https://pan.baidu.com/s/1m3EyAmd_eoAsay0aM7uEkA
提取码:xmfi

第二步:需要在SqlMapConfig.xml中配置插件。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration>

第三步:在查询的sql语句执行之前,添加一行代码:

PageHelper.startPage(1, 10);

  第一个参数是page,要显示第几页。

  第二个参数是rows,没页显示的记录数。

第四步:取查询结果的总数量。

  创建一个PageInfo类的对象,从对象中取分页信息。

PageInfo<TbItem> pageInfo = new PageInfo<>(list);
System.out.println(pageInfo.getTotal());

//测试总结

package com.taotao.controller;

import java.util.List;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemExample; public class testPageHelper { @Test
public void testPageHelper() {
//创建一个 spring 容器
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext*.xml"); //从 spring 容器中获取 TbItemMapper 代理对象
TbItemMapper tbItemMapper = applicationContext.getBean(TbItemMapper.class); //执行查询
TbItemExample example = new TbItemExample(); //分页处理
PageHelper.startPage(1, 10); //第一页 取10条
List<TbItem> list = tbItemMapper.selectByExample(example);
for (TbItem tbItem : list) {
System.out.println(tbItem.getId() + " "+ tbItem.getTitle());
} //取分页信息
PageInfo<TbItem> pageInfo = new PageInfo<>(list);
System.out.println(pageInfo.getTotal());
}
}

pageHelper 分页插件使用的更多相关文章

  1. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

  2. PageHelper分页插件的使用

    大家好!今天写ssm项目实现分页的时候用到pageHelper分页插件,在使用过程中出现了一些错误,因此写篇随笔记录下整个过程 1.背景:在项目的开发的过程中,为了实现所有的功能. 2.目标:实现分页 ...

  3. SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...

  4. mybatis pagehelper分页插件使用

    使用过mybatis的人都知道,mybatis本身就很小且简单,sql写在xml里,统一管理和优化.缺点当然也有,比如我们使用过程中,要使用到分页,如果用最原始的方式的话,1.查询分页数据,2.获取分 ...

  5. spring boot 整合pagehelper分页插件

    Spring Boot 整合pagehelper分页插件 测试环境: spring boot  版本 2.0.0.M7 mybatis starter 版本  1.3.1 jdk 1.8 ------ ...

  6. SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件

    原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...

  7. 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法

    spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...

  8. Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板

    作者:个人微信公众号:程序猿的月光宝盒 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 private int si ...

  9. 逆向工程文件example完美结合使用PageHelper分页插件及分页不成功原因

    原生的mybatis需要手写sql语句,项目数据库表多了之后,可以让你写sql语句写到手软,于是mybatis官方提供了mybatis-generator:mybatis逆向工程代码生成工具,用于简化 ...

  10. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-5.PageHelper分页插件使用

    笔记 5.PageHelper分页插件使用     简介:讲解开源组件,mybaits分页插件的使用 1.引入依赖             <!-- 分页插件依赖 -->          ...

随机推荐

  1. while 循环和do while循环

    while循环是先检测条件符合不符合,符合才执行循环体内容,不符合就跳过while循环. 就和一个房间有两个门,一个前门,一个后门,while循环是当你进入前门的时候有人会检查你的身份,只有身份符合条 ...

  2. 36.LEN() 函数

    LEN() 函数 LEN 函数返回文本字段中值的长度. SQL LEN() 语法 SELECT LEN(column_name) FROM table_name SQL LEN() 实例 我们拥有下面 ...

  3. Luogu 3723 [AH2017/HNOI2017]礼物

    BZOJ 4827 $$\sum_{i = 1}^{n}(x_i - y_i + c)^2 = \sum_{i = 1}^{n}(x_i^2 + y_i^2 + c^2 - 2 * x_iy_i + ...

  4. Nhibernate HQL 匿名类(严格说是map的使用以及构造函数的使用

    1.map的使用 var hql=string.Format(@"select new map( tc.LimitIndexType as LimitIndexType, tc.LimitS ...

  5. codefirst updatebase

    http://blog.csdn.net/dj2008/article/details/23756895 http://blog.csdn.net/gentle_wolf/article/detail ...

  6. MySQL事务隔离级别测试实例

    https://www.cnblogs.com/huanongying/p/7021555.html MySQL事务隔离级别 事务隔离级别 脏读 不可重复读 幻读 读未提交(read-uncommit ...

  7. 我用Django搭网站(1)-新浪微博登录

    新浪微博第三方登录使用的是OAuth2.0,开发前提已经注册开发者帐号,是开发者. OAuth简介 OAuth: OAuth(开放授权)是一个开放标准,允许用户授权第三方网站访问他们存储在另外的服务提 ...

  8. 死磕Java之聊聊HashSet源码(基于JDK1.8)

    HashSet的UML图 HashSet的成员变量及其含义 public class HashSet<E> extends AbstractSet<E> implements ...

  9. 新手必看,Spring Boot CLI 必会必知

    Spring Boot CLI 是什么 Spring Boot CLI 是 Spring Boot Commad Line 的缩写,是 Spring Boot 命令行工具.在 Spring Boot ...

  10. Agreement has been updated--Edit Phone Number最便捷解决办法(不需要安全提示问题和双重认证)

    2018年06月04日亲测有效: CSDN博客跳转网址: