1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
/** * @author Fred Zhu * 分页辅助工具 */ public class PageBean { private int currentPage = 1;// 当前页数 private int totalPages = 0;// 总页数 private int pageSize = 0;// 每页显示数 private int totalRows = 0;// 总数据数 private int startNum = 0;// 开始记录 private int endNum = pageSize;//结束记录 private int nextPage = 0;// 下一页 private int previousPage = 0;// 上一页 private boolean hasNextPage = false;// 是否有下一页 private boolean hasPreviousPage = false;// 是否有前一页 public PageBean(int pageSize, int currentPage, int totalRows) { this.pageSize = pageSize; this.currentPage = currentPage; this.totalRows = totalRows; //计算总页数 if ((totalRows % pageSize) == 0) { totalPages = totalRows / pageSize; } else { totalPages = totalRows / pageSize + 1; } //是否有下一页 if (currentPage >= totalPages) { hasNextPage = false; currentPage = totalPages; } else { hasNextPage = true; } //是否有上一页 if (currentPage <= 1) { hasPreviousPage = false; currentPage = 1; } else { hasPreviousPage = true; } startNum = (currentPage - 1) * pageSize;//开始记录数 if(totalPages-currentPage<1){ endNum = totalRows; }else{ endNum = currentPage*pageSize; } nextPage = currentPage + 1;//下一页页码 previousPage = currentPage - 1;//上一页页码 if (nextPage >= totalPages) { nextPage = totalPages; } if (previousPage <= 1) { previousPage = 1; } } public void refresh(int currentPage){ this.currentPage = currentPage; startNum = (currentPage - 1) * pageSize; if(totalPages-currentPage<1){ endNum = totalRows; }else{ endNum = currentPage*pageSize; } } public boolean isHasNextPage() { return hasNextPage; } public boolean isHasPreviousPage() { return hasPreviousPage; } /** * @return the nextPage */ public int getNextPage() { return nextPage; } /** * @param nextPage * the nextPage to set */ public void setNextPage(int nextPage) { this.nextPage = nextPage; } /** * @return the previousPage */ public int getPreviousPage() { return previousPage; } /** * @param previousPage * the previousPage to set */ public void setPreviousPage(int previousPage) { this.previousPage = previousPage; } /** * @return the currentPage */ public int getCurrentPage() { return currentPage; } /** * @param currentPage * the currentPage to set */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } /** * @return the pageSize */ public int getPageSize() { return pageSize; } /** * @param pageSize * the pageSize to set */ public void setPageSize(int pageSize) { this.pageSize = pageSize; } /** * @return the totalPages */ public int getTotalPages() { return totalPages; } /** * @param totalPages * the totalPages to set */ public void setTotalPages(int totalPages) { this.totalPages = totalPages; } /** * @return the totalRows */ public int getTotalRows() { return totalRows; } /** * @param totalRows * the totalRows to set */ public void setTotalRows(int totalRows) { this.totalRows = totalRows; } /** * @param hasNextPage * the hasNextPage to set */ public void setHasNextPage(boolean hasNextPage) { this.hasNextPage = hasNextPage; } /** * @param hasPreviousPage * the hasPreviousPage to set */ public void setHasPreviousPage(boolean hasPreviousPage) { this.hasPreviousPage = hasPreviousPage; } /** * @return the startNum */ public int getStartNum() { return startNum; } /** * @param startNum * the startNum to set */ public void setStartNum(int startNum) { this.startNum = startNum; } public int getEndNum() { return endNum; } public void setEndNum(int endNum) { this.endNum = endNum; } } |
评论关闭。