All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.antelopeframework.mybatis.paged.PagedQueryRunner Maven / Gradle / Ivy

There is a newer version: 1.1.5
Show newest version
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()); } /** * * @author yangzhi * * @param */ public static interface PagedQueryCallback { List queuy(); } // @Getter // @Setter // public static class Paged implements Serializable { // private static final long serialVersionUID = 1L; // // private final int first; // private final int max; // private final long total; // private final List content; // // public Paged(int first, int max, long total, List content) { // this.first = first; // this.max = max; // this.total = total; // this.content = content; // } // } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy