com.github.antelopeframework.mybatis.paged.PagedQueryRunner Maven / Gradle / Ivy
package com.github.antelopeframework.mybatis.paged;
import java.util.ArrayList;
import java.util.List;
import com.github.antelopeframework.data.support.Paged;
import com.github.antelopeframework.data.support.PagedRequest;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
/**
* MyBatis 分页查询辅助类.
* 使用方式:
*
*
* Paged<Object> pagedResult = PagedQueryRunner.run(0, 3, new PagedQueryCallback<Object>() {
*
* ©Override
* public List<Object> queuy() {
* //MyBatis 查询语句
* }
* });
*
* for (Object one : pagedResult.getContent()) {
* // 业务处理逻辑
* }
*
*
*
* @author yangzhi.yzh
*
*/
public abstract class PagedQueryRunner {
/**
*
* @param first
* @param max
* @param callback
* @return
*/
public static Paged run(Integer first, Integer max, PagedQueryCallback callback) {
if (first == null || first < 0) {
first = 0;
}
if (max == null || max <= 0) {
max = 10;
}
PageHelper.startPage(first / max + 1, max, true);
List queryResult = callback.queuy();
if (queryResult == null) {
return new Paged(new ArrayList());
}
Page ibatisList = ((Page) queryResult);
return new Paged(queryResult, new PagedRequest(first % max, max), ibatisList.getTotal());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy