最近自己在写一个极其简易的快速web开发包,写到分页的部分的时候,出现这个问题public class Pagination {
private int pageCount; // 页数 private int currentPageNo = 1; // 当前页 private int recordNumPerPage = 10; // 每页记录数 private int startRecordId = 0; // 本页开始记录的起始位置 private int recordNumSum; // 记录总条数 private ArrayList<RowModel> pagedList; private ArrayList<RowModel> listForPagination; public Pagination(ArrayList<RowModel> listForPagination,int recordNumPerPage, int currentPageNo) {
this.setListForPagination(listForPagination);
this.setRecordNumPerPage(recordNumPerPage);
this.setCurrentPage(currentPageNo);
this.setRecordNumSum(listForPagination.size());
}
.....
public ArrayList<RowModel> getPagedList() {
if (this.recordNumSum % this.recordNumPerPage == 0) {
this.setPageCount(this.recordNumSum / this.recordNumPerPage);
} else {
this.setPageCount(this.recordNumSum / this.recordNumPerPage + 1);
}
this.setStartRecordId(this.recordNumPerPage * (this.currentPageNo - 1));
System.out.println("[startRecordId] :" + this.startRecordId);
System.out.println("[recordNumPerPage] :" + this.recordNumPerPage);
int startIndex = this.startRecordId;
int endIndex = startIndex + this.recordNumPerPage;
System.out.println("[startIndex]:" + startIndex
+ "           [endIndex]:" + endIndex);
for (int index = startIndex; index < endIndex; index++) {
if (index >= listForPagination.size())
break;
try {
pagedList.add(listForPagination.get(index));
} catch (Exception e) { } }
return pagedList;
}
....
}
这样一个类,省略了一些setter和getter,发现pagedList.add(listForPagination.get(index));没有起作用
最后打出来的pagedList还是null,请问为什么注listForPagination.size()=17这个倒是没问题