一. Mybatis分页插件PageHelper使用

 1、不使用插件如何分页:

使用mybatis实现:

1)接口:

List<Student> selectStudent(Map<String, Object> map);

2)mapper.xml:

<select id="selectStudent" resultMap="BaseResultMap" parameterType="java.util.Map" >
select
<include refid="Base_Column_List" />
from student limit #{pageNum},#{pageSize}
</select>

3)测试:

@Test
public void TestGetStudent() throws IOException {
try {
StudentMapper mapper=session.getMapper(StudentMapper.class);
Map<String,Object> map=new HashMap<String,Object>();
map.put("pageNum", 0);
map.put("pageSize", 3);
List<Student> students=mapper.selectStudent(map); for(Student student :students)
System.out.println(student.gettId() + " " + student.gettName() + " "+student.gettAge()+" "+student.gettEnterdate()+" "+student.gettSid()); }finally {
session.close();
} }

2 使用PageHelper插件如何分页:

下载地址:

https://github.com/pagehelper/Mybatis-PageHelper

https://github.com/JSQLParser/JSqlParser

另外一个地址:

Pagehelper下载地址:

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

jsqlparser 下载地址:

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

使用步骤:

1、导入相关包pagehelper-x.x.x.jar 和  jsqlparser-x.x.x.jar。

2、在MyBatis全局配置文件中配置分页插件。

   <plugins>

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

</plugins>

3、使用PageHelper提供的方法进行分页

  StudentMapper mapper = session.getMapper(StudentMapper.class);
//放在查询之前
Page<Object> page = PageHelper.startPage(1, 3); StudentExample example=null;
List<Student> students=mapper.selectByExample(example); for(Student student :students)
System.out.println(student.gettId() + " " + student.gettName() + " "+student.gettAge()+" "+student.gettEnterdate()+" "+student.gettSid());
System.out.println("当前页码:"+page.getPageNum());
System.out.println("总记录数:"+page.getTotal());
System.out.println("每页的记录数:"+page.getPageSize());
System.out.println("总页码:"+page.getPages());

4、可以使用更强大的PageInfo封装返回结果

           StudentMapper mapper = session.getMapper(StudentMapper.class);
Page<Object> page = PageHelper.startPage(1, 3); StudentExample example=null;
List<Student> students=mapper.selectByExample(example);
for(Student student :students)
System.out.println(student.gettId() + " " + student.gettName() + " "+student.gettAge()+" "+student.gettEnterdate()+" "+student.gettSid());
PageInfo<Student> info = new PageInfo<Student>(students, 3);
System.out.println("当前页码:"+info.getPageNum());
System.out.println("总记录数:"+info.getTotal());
System.out.println("每页的记录数:"+info.getPageSize());
System.out.println("总页码:"+info.getPages());
System.out.println("是否第一页:"+info.isIsFirstPage());
System.out.println("连续显示的页码:");
int[] nums = info.getNavigatepageNums();
for (int i = 0; i < nums.length; i++) {
System.out.println(nums[i]);
}

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

  1. Mybatis分页插件PageHelper的配置和使用方法

     Mybatis分页插件PageHelper的配置和使用方法 前言 在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分 ...

  2. Java SSM框架之MyBatis3(三)Mybatis分页插件PageHelper

    引言 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查询的语句,当查询条件多了之后,会发现真不想花双倍的时间写count和select ...

  3. Mybatis学习---Mybatis分页插件 - PageHelper

    1. Mybatis分页插件 - PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件. 该插件目前支持Oracle,Mysql,MariaDB,S ...

  4. Mybatis分页插件PageHelper的实现

    Mybatis分页插件PageHelper的实现 前言 分页这个概念在做web网站的时候很多都会碰到 说它简单吧 其实也简单 小型的网站,完全可以自己写一个,首先查出数据库总条数,然后按照分页大小分为 ...

  5. 基于Mybatis分页插件PageHelper

    基于Mybatis分页插件PageHelper 1.分页插件使用 1.POM依赖 PageHelper的依赖如下.需要新的版本可以去maven上自行选择 <!-- PageHelper 插件分页 ...

  6. Mybatis分页插件-PageHelper的使用

    转载:http://blog.csdn.net/u012728960/article/details/50791343 Mybatis分页插件-PageHelper的使用 怎样配置mybatis这里就 ...

  7. (转)淘淘商城系列——MyBatis分页插件(PageHelper)的使用以及商品列表展示

    http://blog.csdn.net/yerenyuan_pku/article/details/72774381 上文我们实现了展示后台页面的功能,而本文我们实现的主要功能是展示商品列表,大家要 ...

  8. springmvc mybatis 分页插件 pagehelper

    springmvc mybatis 分页插件 pagehelper 下载地址:pagehelper 4.2.1 , jsqlparser 0.9.5 https://github.com/pagehe ...

  9. MyBatis 分页插件PageHelper 后台报错

    今天遇到一个问题,使用MyBatis 分页插件PageHelper 进行排序分页后,能正常返回正确的结果,但后台却一直在报错 net.sf.jsqlparser.parser.ParseExcepti ...

随机推荐

  1. LINUX 笔记-MOUNT

    mount [-t vfstype] [-o options] device dir -o options: 主要用来描述设备或档案的挂接方式 1)loop:用来把一个文件当成硬盘分区挂上系统 2)r ...

  2. PHP的取整函数

    PHP的取整函数有四个,分别是ceil.floor.round和intval,下面对它们进行一一介绍: 1. ceil(x):向上舍入为最接近的整数. 返回不小于 x 的下一个整数,x 如果有小数部分 ...

  3. LeetCode 1. Two Sum (两数之和)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. Hibernate的基础入门(一)

    一Java三层结构 1 web层:struts框架 2 service层:Spring框架 3  dao层 :hibernate框架 相当于MVC的思想 1 M:模型èhibernate框架 2 V: ...

  5. linq 在查询表达式中处理 null 值

    此示例显示如何在源集合中处理可能的 null 值. IEnumerable<T> 等对象集合可包含值为 null 的元素. 如果源集合为 null 或包含值为 null 的元素,并且查询不 ...

  6. Photoshop颜色出现比较大的偏差,偏色严重,显示器配置文件2351似乎有问题

    其实出现这个问题是因为 显示器的配置问题.并不是PS版本或者电脑系统问题. 一般在你首次启动PS的时候会出现提示:显示器配置文件2351似乎有问题. 如果你点击了继续运行那以后你使用PS打开任何文件都 ...

  7. SQL Server分组查询某最大值的整条数据(包含linq写法)

    想实现如下效果,就是分组后时间最大的那一条数据: 1.SQL SELECT * FROM ( SELECT * , ROW_NUMBER() OVER ( PARTITION BY RIP_GUID ...

  8. 用户需求与NABCD分析

    用户需求与NABCD分析 目录 项目简介 用户需求分析 调研途径 问卷情况说明 问卷反馈与分析 NABCD分析 Need 需求 Approach 途径 Benefit 好处 Competitors 竞 ...

  9. C#脏字过滤算法

    public class DirtyWordOper    {        private static Dictionary<string, object> hash = new Di ...

  10. JavaScript学习笔记(二)——字符串

    在学习廖雪峰前辈的JavaScript教程中,遇到了一些需要注意的点,因此作为学习笔记列出来,提醒自己注意! 如果大家有需要,欢迎访问前辈的博客https://www.liaoxuefeng.com/ ...