MyBatis 分页
分页插件
RowBounds分页
RowBounds分页是MyBatis的内置功能,RowBounds是在返回的sql数据上做截取,一般在数据量不大的场景使用
源代码如下:
package org.apache.ibatis.session; /** * @author Clinton Begin */ 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 final int offset; private final 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; } }
RowBounds中定义了两个主要参数 offset和limit,offset表示从第几行开始读取数据,limit默认值为0,limit则是限制返回的记录数
使用RowBounds
映射XML文件:
<select id="listMap" parameterType="string" resultType="map"> select id,uname,email,address from t_user where uname like concat('%',#{uname},'%') </select>
Mapper接口方法
List<Map> listMap(String uname, RowBounds bounds);
测试代码:
RowBounds bounds = new RowBounds(0, 1); List<Map> data = this.systemUserMapper.listMap("unknown", bounds); Assert.isTrue(data.size() == 1, "返回结果错误");

浙公网安备 33010602011771号