mybatis学习之分页
分页一般分为物理分页:先查询所有值再分页输出,逻辑分页:直接分页查询输出,mybatis支持物理分页,如下:
1、物理分页:
mapper映射:
<select id="findStudents" resultMap="StudentResult">
select * from t_student order by id asc
</select>
Dao接口:
/**
* mybatis分页查询-逻辑分页
* @param rowBounds
* @return
*/
public List<Student> findStudents(RowBounds rowBounds);
测试:
/**
* 逻辑分页----查询所有数据再分页输出
* @throws Exception
*/
@Test
public void testRowBounds() throws Exception{
logger.info("学生查询-逻辑分页");
int offset = 3; //start
int limit = 3; //size
RowBounds rowBounds = new RowBounds(offset,limit);
List<Student> studentList = studentDao.findStudents(rowBounds);
for (Student student : studentList) {
System.out.println(student);
}
}
2、逻辑分页:
mapper映射:
<select id="findStudents2" parameterType="Map" resultMap="StudentResult">
select * from t_student
<if test="start != null and size != null">
limit #{start},#{size}
</if>
</select>
Dao接口:
/**
* mybatis分页查询-物理分页
* @param rowBounds
* @return
*/
public List<Student> findStudents2(Map<String, Object> map);
测试:
/**
* 物理分页----查询分页数据再输出
* @throws Exception
*/
@Test
public void testFind() throws Exception{
logger.info("学生查询-物理分页");
Map<String, Object> map = new HashMap<>();
map.put("start", 0);
map.put("size", 3);
List<Student> studentList = studentDao.findStudents2(map);
for (Student student : studentList) {
System.out.println(student);
}
}
mybatis学习之分页的更多相关文章
- Mybatis学习 PageHelper分页插件
1.Maven依赖,注意使用PageHelper时的版本必须与Mybatis版本对应 1 <!-- 添加Mybatis依赖 --> 2 <dependency> 3 <g ...
- mybatis学习——实现分页
首先回顾一下分页的sql语句: SELEC * FROM 表名 LIMIT startIndex,pageSize tips: *startIndex:起始的位置(从哪个元素开始分页) *pageSi ...
- Mybatis学习笔记-分页
为何要分页 减少数据处理量 便于前端展示数据 使用Limit分页 语法结构 SELECT * FROM user LIMIT startIndex,pageSize; SELECT * FROM us ...
- Mybatis学习笔记导航
Mybatis小白快速入门 简介 本人是一个Java学习者,最近才开始在博客园上分享自己的学习经验,同时帮助那些想要学习的uu们,相关学习视频在小破站的狂神说,狂神真的是我学习到现在觉得最GAN的老师 ...
- 【Todo】Mybatis学习-偏理论
之前写过好几篇Mybatis相关的文章: http://www.cnblogs.com/charlesblc/p/5906431.html <SSM(SpringMVC+Spring+Myba ...
- MyBatis学习总结(二)——MyBatis核心配置文件与输入输出映射
在上一章中我们学习了<MyBatis学习总结(一)——ORM概要与MyBatis快速起步>,这一章主要是介绍MyBatis核心配置文件.使用接口+XML实现完整数据访问.输入参数映射与输出 ...
- MyBatis学习总结(三)——多表关联查询与动态SQL
在上一章中我们学习了<MyBatis学习总结(二)——MyBatis核心配置文件与输入输出映射>,这一章主要是介绍一对一关联查询.一对多关联查询与动态SQL等内容. 一.多表关联查询 表与 ...
- mybatis学习--缓存(一级和二级缓存)
声明:学习摘要! MyBatis缓存 我们知道,频繁的数据库操作是非常耗费性能的(主要是因为对于DB而言,数据是持久化在磁盘中的,因此查询操作需要通过IO,IO操作速度相比内存操作速度慢了好几个量级) ...
- Mybatis学习---基础知识考核
MyBatis 2.什么是MyBatis的接口绑定,有什么好处 接口映射就是在IBatis中任意定义接口,然后把接口里面的方法和SQL语句绑定, 我们直接调用接口方法就可以,这样比起原来了Sql ...
随机推荐
- RAID 介绍
介绍 磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意. 磁盘阵列是由很多价格较便宜的磁盘,组合成一个容量巨 ...
- OCP 052新加的考试题收集整理-第20道
20. Which is true about the SYSTEM and SYSAUX tablespaces? A) The SYSAUX tablespace can be made read ...
- jQuery滚动到特定位置时出现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- nginx负载均衡监测节点状态
1. 安装nginx_upstream_check_module模块 我的实验环境是在/root 和 /application目录下都编译安装了nginx-1.6.3,然后在/root目录下建立一个文 ...
- HEOI2019游记(退役记)
少了回程铁路相关信息,有空补 AFO 辣鸡蒟蒻ghj1222顺利地退役了 由于没带手机拍照片,本次坐动车不写运转记录,下次去CTS/APIO应该是坐普速车,应该能带手机拍照,应该会写运转记录 Day ...
- js中的类和对象以及自定义对象
js中的类 1.类的声明 function Person(name,age){ this.name=name; this.age=age; this.test=function(a){ alert(a ...
- React第二篇:组件的生命周期
前言:因为生命周期是必须要掌握的,所以React的第二篇咱就写这. (版本:16.3.2) React的生命周期大致分为四个状态:分别是Mouting.Updating.Unmounting.Erro ...
- L2-3 名人堂与代金券 (25 分)
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; int N, ...
- PHP打开错误提示和关闭错误提示的方法
找到php的配置文件,也就是php.ini 在文件中查找 ‘display_errors’ 查找到 display_errors = Off 或者 display_errors = On, Off ...
- Python爬虫常用之登录(一) 思想
爬虫主要目的是获取数据,常见的数据可以直接访问网页或者抓包获取,然后再解析即可. 一些较为隐私的数据则不会让游客身份的访问者随便看到,这个时候便需要登录获取. 一般获取数据需要的是登录后的cookie ...