Mybatis RowBounds分页机制是如何实现详细解析?
- 内容介绍
- 文章标签
- 相关推荐
本文共计710个文字,预计阅读时间需要3分钟。
Mybatis通过传递RowBounds对象,实现对数据库数据的分页操作,其原理是对ResultSet结果集进行分页,而非物理分页。RowBounds对象的作用,是将分页的起始行和结束行传递给数据库查询,实现逻辑分页。
Mybatis可以通过传递RowBounds对象,来进行数据库数据的分页操作,然而遗憾的是,该分页操作是对ResultSet结果集进行分页,也就是人们常说的逻辑分页,而非物理分页。
RowBounds对象的源码如下:
public class RowBounds { public static final int NO_ROW_OFFSET = 0; public static final int NO_ROW_LIMIT = Integer.MAX_VALUE; public static final RowBounds DEFAULT = new RowBounds(); private int offset; private int limit; public RowBounds() { this.offset = NO_ROW_OFFSET; this.limit = NO_ROW_LIMIT; } public RowBounds(int offset, int limit) { this.offset = offset; this.limit = limit; } public int getOffset() { return offset; } public int getLimit() { return limit; } }
对数据库数据进行分页,依靠offset和limit两个参数,表示从第几条开始,取多少条。
本文共计710个文字,预计阅读时间需要3分钟。
Mybatis通过传递RowBounds对象,实现对数据库数据的分页操作,其原理是对ResultSet结果集进行分页,而非物理分页。RowBounds对象的作用,是将分页的起始行和结束行传递给数据库查询,实现逻辑分页。
Mybatis可以通过传递RowBounds对象,来进行数据库数据的分页操作,然而遗憾的是,该分页操作是对ResultSet结果集进行分页,也就是人们常说的逻辑分页,而非物理分页。
RowBounds对象的源码如下:
public class RowBounds { public static final int NO_ROW_OFFSET = 0; public static final int NO_ROW_LIMIT = Integer.MAX_VALUE; public static final RowBounds DEFAULT = new RowBounds(); private int offset; private int limit; public RowBounds() { this.offset = NO_ROW_OFFSET; this.limit = NO_ROW_LIMIT; } public RowBounds(int offset, int limit) { this.offset = offset; this.limit = limit; } public int getOffset() { return offset; } public int getLimit() { return limit; } }
对数据库数据进行分页,依靠offset和limit两个参数,表示从第几条开始,取多少条。

