引入pageHelper
来源:互联网 发布:全国省市区sqlserver 编辑:程序博客网 时间:2024/05/18 00:09
pageHelper4
* 支持条件查询
* 支持条件分页排序
一、使用方法
第一步:引入pageHelper的jar包。 pagehelper-4.1.1.jar
依赖jar jsqlparser-0.9.4.jar
第二步:需要在SqlMapConfig.xml中配置插件。
注意:pageHelper4 mybatis版本需要至少3.3 测试版本3.3
<configuration><!-- 别名 --><typeAliases><package name="com.xyj.ssm.po"/></typeAliases><!-- 配置分页插件 --><plugins><plugin interceptor="com.github.pagehelper.PageHelper"><!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库--> <property name="dialect" value="mysql"/></plugin></plugins><!-- mapper 使用spring扫描 所以不需要配置 但是需要遵循规范 --></configuration>
特别注意:在Mybatis配置xml中配置拦截器插件:
<!-- plugins在配置文件中的位置必须符合要求,否则会报错,顺序如下: properties?, settings?, typeAliases?, typeHandlers?, objectFactory?,objectWrapperFactory?, plugins?, environments?, databaseIdProvider?, mappers?-->
第三步:在查询的sql语句执行之前,添加一行代码:
PageHelper.startPage(1, 10);
第一个参数是page,要显示第几页。
第二个参数是rows,每页显示的记录数。
第四步:取查询结果的总数量。
创建一个PageInfo类的对象,从对象中取分页信息。
public static void main(String[] args) {ApplicationContext app = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");// 使用mapper查询数据库ShopcouponcountMapper mapper = app.getBean(ShopcouponcountMapper.class);ShopcouponcountExample example = new ShopcouponcountExample();Criteria criteria = example.createCriteria();criteria.andUseridEqualTo(6);// 设置分页PageHelper.startPage(1, 10 , "scId desc");List<Shopcouponcount> list = mapper.selectByExample(example);for (Shopcouponcount shopcouponcount : list) {System.out.println(shopcouponcount.getCount());}PageInfo<Shopcouponcount> pageInfo = new PageInfo<Shopcouponcount>(list);System.out.println("共有数据" + pageInfo.getTotal() );}
注意:
PageHelper.startPage(1, 10); 页号必须从1 开始,否则取不到数据
阅读全文
0 0
- 引入pageHelper
- pageHelper
- PageHelper
- PageHelper
- PageHelper
- pagehelper
- pagehelper
- pageHelper浅尝
- PageHelper插件
- pageHelper插件
- PageHelper分页
- Mybatis-PageHelper
- pagehelper分页
- mybatis之PageHelper
- MyBatis分页插件PageHelper
- mybatis分页插件pagehelper
- Mybaties PageHelper分页插件
- 笔记--PageHelper分页
- MQ学习(四)--- 与spring整合(点对点模式)
- Thrift在Android上的客户端实现
- C++数组概述
- LeetCode 563. Binary Tree Tilt (C++)
- 系统学习 jQuery (二) 工具
- 引入pageHelper
- iOS 按比例显示图片 切割后显示中心图片(缩略图)
- 更改UITextField的placeholder文字颜色的5种方法
- Linux服务器简单设置minicom
- 多重排列和多重组合
- iOS
- 64位Pring2Flash转换器
- EventBus使用详解(一)——初步使用EventBus
- 常用分析日志shell命令