第一步:引入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. PCL点云库中的坐标系(CoordinateSystem)

    博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...

  2. ubuntu 设置虚拟机和主机在同一网段

    一.在VMware中将网络连接方式设置为桥接 1.打开VM菜单栏->Settings 2.在弹出的Virtual Machine Setting对话框中点击Network Adapter,在右边 ...

  3. 解决error C2365

    今天把一个FILE_BOTH_DIRECTORY_INFORMATION结构的变量,愣是写成了“enum”枚举....然后出现error C2365错误. 在CSDN上看到别人遇到问题,有人回复了“如 ...

  4. Luogu 4244 [SHOI2008]仙人掌图

    BZOJ 1023 如果我们把所有的环都缩成一个点,那么整张图就变成了一棵树,我们可以直接$dp$算出树的直径. 设$f_x$表示$x$的子树中最长链的长度,那么对于$x$的每一个儿子$y$,先用$f ...

  5. Ajax——jQuery实现

    紧接上文 一.load()方法 load() 方法师jQuery中最为简单和常用的Ajax方法,能载入远程的HTML代码并插入到DOM中.它的机构是:load(url[,data][,callback ...

  6. servlet-向页面输出中文出现乱码处理方式

    package cn.lijun .content; import java.io.IOException;import java.io.PrintWriter; import javax.servl ...

  7. javascript总结1:js常见页面消息输出方式 alert confirm console prompt document

    .1 js常见的输出方法: 1-1 alert 警告框 alert("js语法总结"); 1-2 confirm 确认方法 confirm("js语法总结"); ...

  8. UVa 1625 Color Length (DP)

    题意:给定两个序列,让你组成一个新的序列,让两个相同字符的位置最大差之和最小.组成方式只能从一个序列前部拿出一个字符放到新序列中. 析:这个题状态表示和转移很容易想到,主要是在处理上面,dp[i][j ...

  9. javax.servlet.jsp.PageContext cannot be resolved to a type

    <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifa ...

  10. Daubechies Wavelet

    The Daubechies wavelets, based on the work of Ingrid Daubechies, are a family of orthogonal wavelets ...