工具类——(集合分页类)

import java.util.ArrayList;
import java.util.List;
/**
 * 集合分页类
 * @author xu
 *
 */
public class ListPageHelper {
	/**
	 * 
	 * @param pageNo
	 *            当前页码
	 * @param pageSize
	 *            页数
	 * @param list
	 *            所有集合
	 * @return
	 * @throws Exception
	 */
	public static List page(int pageNo, int pageSize, List list) throws Exception {
		List result = new ArrayList();
		if (list != null && list.size() > 0) {
			int allCount = list.size();
			int pageCount = (allCount + pageSize - 1) / pageSize;
			if (pageNo >= pageCount) {
				pageNo = pageCount;
			}
			int start = (pageNo - 1) * pageSize;
			int end = pageNo * pageSize;
			if (end >= allCount) {
				end = allCount;
			}
			for (int i = start; i < end; i++) {
				result.add(list.get(i));
			}
		}
		return (result != null && result.size() > 0) ? result : null;
	}
}
 
  

 

你可能感兴趣的:(工具类,List,ArarryList)