验证中...
私信发送成功
语言: Java
分类: 网络技术
最后更新于 2018-01-13 18:14
片段 1 片段 2 片段 3
List分页
原始数据 复制代码
package com.creditall.service.core.util;
import java.util.List;
/**
* created by aladin
* 2018/1/11
* 分页工具类
*/
public class ListPageUtils {
/**
* 分页,定义当前页,跳转动作,页面大小,直接跳转和要实现分页的list
* 返回结果:
* 1.分好的list
* 2.list起始位(包含)
* 3.list结束位(不包含)
* @param currentPage
* @param pageAction
* @param pageSize
* @param jumpPage
* @param list
* @return
*/
public static ListPageResult listDev(Integer currentPage,Integer pageAction,Integer pageSize,Integer jumpPage,List list){
ListPage myPage = new ListPage();
myPage.setCurrentPage(currentPage);
myPage.setPageAction(pageAction);
myPage.setPageSize(pageSize);
myPage.setJumpedPage(jumpPage);
return ListPageUtils.listDev(myPage,list);
}
/**
* 分页,定义当前页,跳转动作,页面大小,直接跳转和要实现分页的list
* 返回结果:
* 1.分好的list
* 2.list起始位(包含)
* 3.list结束位(不包含)
*/
public static ListPageResult listDev(ListPage myPage,List list){
if(list.size()==0){
return ListPageUtils.emptyListPageDivResult();
}
if(myPage.getCurrentPage()==null||myPage.getPageAction()==null||myPage.getPageSize()==null){
myPage.setCurrentPage(0);
myPage.setPageAction(0);
}
if(myPage.getJumpedPage()!=null) {
myPage.setPageAction(0);
if (myPage.getJumpedPage().equals(-1)) {
myPage.setCurrentPage((int) Math.floor(list.size()/myPage.getPageSize()));
} else {
myPage.setCurrentPage(myPage.getJumpedPage());
}
}
ListPageResult listPageResult = new ListPageResult();
listPageResult.setList(ListPageUtils.returnList(list,myPage.getCurrentPage(), myPage.getPageAction(), myPage.getPageSize()));
Integer[] listBeginAndEnd = ListPageUtils.pageDevHelper(list,myPage.getCurrentPage(), myPage.getPageAction(), myPage.getPageSize());
listPageResult.setBeginIndex(listBeginAndEnd[0]);
listPageResult.setEndIndex(listBeginAndEnd[1]);
return listPageResult;
}
public static List returnList (List list,Integer currentPage,Integer pageAction,Integer pageSize){
Integer[] listBeginAndEnd = ListPageUtils.pageDevHelper(list,currentPage,pageAction,pageSize);
Integer start = listBeginAndEnd[0];
Integer end = listBeginAndEnd[1];
list = list.subList(start,end);
return list;
}
public static Integer[] pageDevHelper(List list,Integer currentPage,Integer pageAction,Integer pageSize){
Integer listSize = list.size();
Integer listBeginAndEnd[] = new Integer[]{0,listSize};
if(currentPage==null||pageAction==null||pageSize==null){
return listBeginAndEnd;
}
Integer nextPage = currentPage+pageAction;
if(nextPage<0){
return listBeginAndEnd;
}
Integer start = nextPage*pageSize;
Integer fakeEnd = (nextPage+1)*pageSize;
Integer end = Math.min(fakeEnd,listSize);
if(start>=end){
start = end-1;
}
listBeginAndEnd =new Integer[] {start,end};
return listBeginAndEnd;
}
public static ListPageResult emptyListPageDivResult(){
ListPageResult emptyListPageDivResult = new ListPageResult();
emptyListPageDivResult.setBeginIndex(0);
emptyListPageDivResult.setEndIndex(1);
return emptyListPageDivResult;
}
}
ListPage
原始数据 复制代码
package com.creditall.service.core.util;
/**
* created by aladin
* 2018/1/11
* 用来给list分页的工具类对象
*/
public class ListPage {
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageAction() {
return pageAction;
}
public void setPageAction(Integer pageAction) {
this.pageAction = pageAction;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getJumpedPage() {
return jumpedPage;
}
public void setJumpedPage(Integer jumpedPage) {
this.jumpedPage = jumpedPage;
}
private Integer currentPage;
private Integer pageAction;
private Integer pageSize;
private Integer jumpedPage;
}
ListPageResult
原始数据 复制代码
package com.creditall.service.core.util;
import java.util.List;
/**
* created by aladin
* 2018/1/11
* 用来给list分页的工具类对象,保存处理结果
*/
public class ListPageResult {
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public Integer getBeginIndex() {
return beginIndex;
}
public void setBeginIndex(Integer beginIndex) {
this.beginIndex = beginIndex;
}
public Integer getEndIndex() {
return endIndex;
}
public void setEndIndex(Integer endIndex) {
this.endIndex = endIndex;
}
private List list;
private Integer beginIndex;
private Integer endIndex;
}

评论列表( 0 )

你可以在登录后,对此项目发表评论

6_float_left_people 6_float_left_close