`

分页的一小段代码,比较健忘,存着自己用

    博客分类:
  • web
阅读更多
				int total = Integer.parseInt(totalNum);
				int allPages = total % 10 == 0 ? total / 10 : total / 10 + 1;

				int pageLength = allPages > 9 ? 9 : allPages;

				int pagearr[] = new int[pageLength];

				if (page > 4) {
					if (allPages - page > 4) {
						for (int i = 0; i < 4; i++) {
							pagearr[i] = page + i - 4;
							pagearr[5 + i] = page + i + 1;
						}
						pagearr[4] = page;
					} else if (allPages > 9) {
						for (int i = 0; i < pageLength; i++) {
							pagearr[i] = allPages + i - 8;
						}
					} else {
						for (int i = 0; i < pageLength; i++) {
							pagearr[i] = i + 1;
						}
					}
				} else {
					for (int i = 0; i < pageLength; i++) {
						pagearr[i] = i + 1;
					}
				}

 

jsp片断

 

<c:if test="${page>1}">
										<a
											href="<%=path%>/com/fullSeach.do?page=${page-1 }&q=${q }&type=${type }" class="prev-page">上一页
										</a>
									</c:if>
									<c:forEach items="${pages}" var="p">

										<c:choose>
											<c:when test="${p==page}">
												<span class="current-page">${p }</span>

											</c:when>
											<c:otherwise>
												<a
													href="<%=path%>/com/fullSeach.do?page=${p }&q=${q }&type=${type }">${p
													}</a>
											</c:otherwise>
										</c:choose>
									</c:forEach>

									<c:if test="${page<maxPage}">
										<a
											href="<%=path%>/com/fullSeach.do?page=${page+1 }&q=${q }&type=${type }" class="next-page">下一页
										</a>
									</c:if>
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics