|
|
@@ -205,5 +205,38 @@ public class PageUtils implements Serializable {
|
|
|
return list.subList(fromIndex,toIndex);
|
|
|
}
|
|
|
|
|
|
+ public static <T> List<T> getPageList(List<T> list,int current,int pageSize){
|
|
|
+ if(list ==null){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ if(list.size() == 0){
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ if(current ==0){
|
|
|
+ current = 1;
|
|
|
+ }
|
|
|
+ //记录总数
|
|
|
+ int count = list.size();
|
|
|
+ //页数
|
|
|
+ int pageCount = 0;
|
|
|
+ if(count % pageSize==0){
|
|
|
+ pageCount = count / pageSize;
|
|
|
+ }else {
|
|
|
+ pageCount = count / pageSize + 1;
|
|
|
+ }
|
|
|
+ int fromIndex = 0;
|
|
|
+ int toIndex = 0;
|
|
|
+ if(current>pageCount){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ if(current != pageCount){
|
|
|
+ fromIndex = (current - 1)*pageSize;
|
|
|
+ toIndex = fromIndex + pageSize;
|
|
|
+ }else {
|
|
|
+ fromIndex = (current - 1)*pageSize;
|
|
|
+ toIndex = count;
|
|
|
+ }
|
|
|
+ return list.subList(fromIndex,toIndex);
|
|
|
+ }
|
|
|
|
|
|
}
|