1.分页处理方法:
package com.yuezhu.utils;
import org.apache.commons.lang.StringUtils;
/**
* Created by Administrator on 2017/7/12.
*/
public class GetRowsUtil {
public static int getPage(String page , String rows){
if (StringUtils.isNotBlank(rows) && StringUtils.isNotBlank(page)) {
int p = Integer.valueOf(page);
int r = Integer.valueOf(rows);
return (p-1)*r;
}else{
return 0;
}
}
public static int getRows(String rows){
if (StringUtils.isNotBlank(rows)){
return Integer.valueOf(rows);
}else{
return 10;
}
}
}
2.在List集合中进行分页查询:
package net.longjin.comm.utils; import java.util.List; /** * 描述:PageUtils * * @author 何志鹏 * @ClassName:PageUtils * @create 2019-05-29 19:13 * Version 1.0 */ public class PageUtils { public static <T>List<T> PageHelper(int page, int rows, List<T> list) { int size = list.size(); int pageCount=size/rows; int fromIndex = rows * (page - 1); int toIndex = fromIndex + rows; if (toIndex >= size) { toIndex = size; }else if(page>=pageCount+1){ fromIndex=0; toIndex=0; } List<T> dutyPatrols = null; try { dutyPatrols = list.subList(fromIndex, toIndex); } catch (Exception e) { dutyPatrols = null; } return dutyPatrols; } }