list 分页

package com.jsz.peini.common.util;

import java.util.ArrayList;
import java.util.List;

public class SubListUtil {

public static List<Object> fenye(List list, int pagenum, int pagesize) {

int totalcount = list.size();
int pagecount = 0;
int m = totalcount % pagesize;
if (m > 0) {
pagecount = totalcount / pagesize + 1;
} else {
pagecount = totalcount / pagesize;
}

// for(int i=1;i<=pagecount;i++){
if (m == 0) {
List<Object> subList = list.subList((pagenum - 1) * pagesize, pagesize * (pagenum));
return subList;
} else {
if (pagenum == pagecount) {
List<Object> subList = list.subList((pagenum - 1) * pagesize, totalcount);
return subList;
} else if (pagenum > pagecount) {
return new ArrayList<Object>();
} else {
List<Object> subList = list.subList((pagenum - 1) * pagesize, pagesize * (pagenum));
return subList;
}

// }
}

}

public static void main(String[] args) {

List<Object> list = new ArrayList<Object>();
for (int i = 1; i < 52; i++) {
list.add(i);
}

fenye(list, 10, 10);

}
}
 

 

 int pagenum, int pagesize  传过来参数的时候 这两个需要调换位置 懒得改方法
posted @ 2017-08-02 15:55  咸蛋超人、  阅读(173)  评论(0编辑  收藏  举报