mybatis的分页插件pageHelper
来源:互联网 发布:中国统一台湾 知乎 编辑:程序博客网 时间:2024/04/29 09:44
https://github.com/pagehelper/Mybatis-PageHelper/tree/master/src/main/java/com/github/pagehelper
实现原理:
使用方法:
1、引入jar包
2、
3、在查询的sql语句执行之前,添加一行代码:
需要在SqlMapConfig.xml中配置插件
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//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>
3、在查询的sql语句执行之前,添加一行代码:
PageHelper.startPage(1, 10);
第一个参数是page,要显示第几页。
第二个参数是rows,没页显示的记录数。
4、取查询结果的总数量。
创建一个PageInfo类的对象,从对象中取分页信息。
public class TestPageHelper {@Testpublic void testPageHelper(){//1、创建一个Spring容器ApplicationContext applicationContext=new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");//2、从Spring容器中获取mapper对象TbItemMapper bean = applicationContext.getBean(TbItemMapper.class);//3、执行sql并分页TbItemExample example=new TbItemExample();//4、分页处理PageHelper.startPage(1, 6);List<TbItem> selectByExample = bean.selectByExample(example);System.out.println(selectByExample.size());for (TbItem tbItem : selectByExample) {System.out.println(tbItem.getTitle());}PageInfo<TbItem> pages=new PageInfo<>(selectByExample);long total = pages.getTotal();System.out.println("总记录数============"+total);}}
0 0
- mybatis的分页插件pageHelper
- pagehelper mybatis的分页插件
- mybatis的分页插件pageHelper
- 【MyBatis】MyBatis分页插件PageHelper的使用
- 【MyBatis】MyBatis分页插件PageHelper的使用
- 【MyBatis】MyBatis分页插件PageHelper的使用
- MyBatis分页插件PageHelper
- mybatis分页插件pagehelper
- Mybatis分页插件-pagehelper
- Mybatis分页插件 - PageHelper
- Mybatis分页插件PageHelper
- Mybatis分页插件PageHelper
- MyBatis分页插件PageHelper
- mybatis插件分页PageHelper
- Mybatis分页插件PageHelper
- Mybatis分页插件PageHelper
- mybatis分页插件 PageHelper
- 【mybatis】分页插件PageHelper
- List 排序
- 面试题:1,进程和线程的区别?什么时候用进程?什么时候用线程?为什么你的项目中用的是线程?为什么不用进程?如果只有进程,对你这个项目有没有影响?
- acm 最后总结
- spring proxy-target-class
- Excel导出JAVA
- mybatis的分页插件pageHelper
- Jquery 元素遍历,取值
- 面试题:谈谈对进程的理解?谈谈你对线程的理解?2.进程死锁的原因?如何解决进程死锁?
- String转Int
- 内部エラー -選択したファイルは変更できないシステムファイルです。これは表示されません
- [2.5]详解spark sql用户自定义函数:UDF与UDAF
- 鼠标停留变换颜色(以颜色为例)的2种方法
- android项目中实现百度地图中点聚合功能
- CSS3自定义radio