使用Mybatis如何对Mysql进行分页功能?
使用Mybatis如何对Mysql进行分页功能
1、Limit实现分页
接口
//分页List<User> getUserByLimit(HashMap<String, Integer> map);
Mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!--namespace=绑定一个对应的Dao/Mapper接口-->
<mapper namespace="com.kk.dao.UserMapper"><!-- 结果集映射--><resultMap id="UserMap" type="User">
<!-- column数据库中大的字段 property实体类中的属性-->
<!-- <result column="id" property="id"></result>-->
<!-- <result column="name" property="name"></result>--><result column="pwd" property="password"></result></resultMap><!-- select查询语句--><select id="getUserById" parameterType="int" resultMap="UserMap" >select * from mybatis.user where id = #{id};</select><!-- 分页--><select id="getUserByLimit" parameterType="map" resultMap="UserMap">select * from mybatis.user limit #{startIndex},#{pageSize};</select></mapper>
测试
//分页@Testpublic void getUserByLimit() {SqlSession sqlSession = MybatisUtil.getSqlSession();UserMapper mapper = sqlSession.getMapper(UserMapper.class);HashMap<String, Integer> map = new HashMap<String,Integer>();map.put("startIndex",0);map.put("pageSize",2);List<User> userList= mapper.getUserByLimit(map);for (User user : userList) {System.out.println(user);}sqlSession.close();}
2、RowBounds实现分页
不使用SQL实现分页
接口
//分页2
List<User> getUserByRowBounds();
Mapper.xml
<!-- 分页2-->
<select id="getUserByRowBounds" resultMap="UserMap">select * from mybatis.user
</select>
测试
//分页2
@Test
public void getUserByRowBounds(){SqlSession sqlSession = MybatisUtil.getSqlSession();//RowBound实现RowBounds rowBounds = new RowBounds(1, 2);//通过Java层面实现分页List<User> userList = sqlSession.selectList("com.kk.dao.UserMapper.getUserByRowBounds",null,rowBounds);for (User user : userList) {System.out.println(user);}sqlSession.close();
}
3.分页插件 (mybatis pagehelper)
了解即可
使用Mybatis如何对Mysql进行分页功能?相关推荐
- 转:mybatis - 分页功能
本文转自http://www.cnblogs.com/jcli/archive/2011/08/09/2132222.html mybatis高级应用系列一:分页功能 Mybatis3.0出来已有段时 ...
- Mybatis+MySQL动态分页查询数据经典案例
最近在用Mybatis做项目的时候遇到了不少问题,今天我就在这和大家分享一下,稀稀拉拉的研究了两天,终于搞好了! 开发人员:1111 开发软件:Myeclipse 用到的框架技术:Mybatis 数据 ...
- Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
最近在用Mybatis做项目的时候遇到了不少问题,今天我就在这和大家分享一下,稀稀拉拉的研究了两天,终于搞好了! 开发人员:1111 开发软件:Myeclipse 用到的框架技术:Mybatis 数据 ...
- Mybatis分页功能 pagehelper插件
Mybatis分页功能 pagehelper插件 创建数据数据 use ssm; create table student (id int auto_incrementprimary key,name ...
- spring boot+mybatis+thymeleaf+pagehelper分页插件实现分页功能
文章目录 前言 正文 业务场景 后端 pom.xml application.yml 实体类video.java和User.java----映射VideoMapper.xml----VideoMapp ...
- mybatis mysql rownum_MyBatis怎样实现MySQL动态分页?
在这些控件里要达到分页的效果,一般都会传2个参数,第一个是表示当前页的索 引(一般从0开始),第二个表示当前页展示多少条业务记录,然后将相应的参数传递给List getList(PagenateArg ...
- mysql sqlite 分页查询_php基于SQLite实现的分页功能示例
本文实例讲述了php基于SQLite实现的分页功能.分享给大家供大家参考,具体如下: 这里操作数据库文件使用的是前面文章<PHP基于PDO实现的SQLite操作类[包含增删改查及事务等操作]&g ...
- mybatis-generator 插件扩展,生成支持多种数据库的分页功能
2019独角兽企业重金招聘Python工程师标准>>> 背景: 在使用mybatis的过程中,考虑到整合的框架在后期使用的过程中,有可能是需要兼容到多种数据库的,在这种前提条件下,完 ...
- Spring Boot入门系列(十六)整合pagehelper,一秒实现分页功能!
之前讲了Springboot整合Mybatis,然后介绍了如何自动生成pojo实体类.mapper类和对应的mapper.xml 文件,并实现最基本的增删改查功能.接下来要说一说Mybatis 的分页 ...
最新文章
- JAVA课程设计——“小羊吃蓝莓”小游戏
- 【Android 高性能音频】Oboe 开发流程 ( 检查 Oboe 音频流属性 | 开始播放 | 停止播放 | 关闭 Oboe 音频流 | 重新配置 Oboe 音频流属性 )
- makefile文件编写_九图记住Makefile
- 升级Struts2.5后使用DMI动态方法调用遇到问题
- plsql 常用函数
- 单行文本和多行文本溢出以省略号显示方法
- linux系统制作win安装盘,在Ubuntu Linux下制作Windows 启动安装 USB盘
- 设计模式12——代理模式
- 联想台式主机拆机教程_联想r400拆机教程 拆解电脑没那么难
- 《认识我们人类自己》江湖一剑客
- python怎么加图片_python图片加水印
- PB编程常用API函数
- 泰森多边形的matlab实现
- 计算机怎么样返回桌面,电脑如何快速返回桌面
- 【无线】【流程】QCA无线驱动收包流程分析
- 多用户php商城 开源,php多用户商城选择开源的好
- css3滤镜属性filter实现网页变黑白效果
- 共享安装 cacti 过程中的一些经历 cacti 中文-linux - sun solaris
- STP基础(锐捷、H3C交换机开启STP)
- 微信小程序 | 基于云数据库的许愿墙
热门文章
- C# Cookies揭秘 [Asp.Net, Javascript]
- 11,一道关于栈内存分配的题目
- 数据挖掘你真的了解吗?
- win10无法新建文件夹怎么办 win10右键新建菜单设置方法
- Swing学习笔记1-----Swing组件类的层次
- SpringMVC学习总结(三)——Controller接口详解(1)
- MVC.NET:提供对字体文件.woff的访问
- Nginx压测性能优化
- 概率论与数理统计 (二)计算题和应用题
- spring设置全局异常处理器