Mybatis默认的分页是通过RowBounds参数来实现的,并且是在内存里面进行的,我们看一下整体的流程
在获取MapperMethod的时候我们发现,通过方法的入参是否有RowBounds参数来判断是否分页
this.rowBoundsIndex = getUniqueParamIndex(method, RowBounds.class);
private Integer getUniqueParamIndex(Method method, Class<?> paramType) {
Integer index = null;
//获取当前方法的所有入参类型
final Class<?>[] argTypes = method.getParameterTypes();
//循环所有的入参类型
for (int i = 0; i < argTypes.length; i++) {
//这里判断入参是否有我们需要的类型,如果有获取参数的下标
if (paramType.isAssignableFrom(argTypes[i])) {
if (index == null) {
index = i;
} else {
throw new BindingException(method.getName() + " cannot have multiple " + paramType.getSimpleName() + " parameters");
}
}
}
在查询的方法中