标签:
page.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<div>
当前${page.pageNo } 页/共${page.totalPage } 页
<a href="${page.url }?pageNo=${page.prep}">上一页</a>
<!-- 滚动数字 -->
<c:forEach begin="${page.beginPageno }" end="${page.endPageno }" var="no">
<a href="${page.url }?pageNo=${no}">${no }</a>
</c:forEach>
<a href="${page.url }?pageNo=${page.nextp}">下一页</a>
选择<select onchange="changePage(this)">
<c:forEach begin="1" end="${page.totalPage }" var="i">
<option value="${i }" ${page.pageNo==i?"selected=‘selected‘":"" }>${i }</option>
</c:forEach>
</select>页
<script>
function changePage(objOpt){
window.location.href="${page.url}?pageNo="+objOpt.value;
}
</script>
</div>
PageBean.java
package com.itheima.utils;
import java.io.Serializable;
import java.util.List;
public class PageBean implements Serializable {
private int pageNo=1;//当前页
private int pageSize=3;//每页显示的记录数
private int prep;//上一页
private int nextp;//下一页
private int totalPage;//总页数
private int totalRecordes;//总记录数
private List recordes;// 当前页的记录
private int startIndex;//当前页的第一条记录的索引 limit startIndex,size
//为了加入滚动数字
private int beginPageno;
private int endPageno;
public int getBeginPageno() {
//设置页码 1 2 3 4 5 6 7 8 9 (看到的数字)
if(pageNo<=9){
beginPageno=1;
endPageno = this.getTotalPage();//总记录数
}else{
//说明当前页已超出9
beginPageno=pageNo-4;
endPageno = pageNo+4;
if(beginPageno<=0)
beginPageno=1;
if(endPageno>getTotalPage())
endPageno=this.getTotalPage();
}
return beginPageno;
}
public void setBeginPageno(int beginPageno) {
this.beginPageno = beginPageno;
}
public int getEndPageno() {
return endPageno;
}
public void setEndPageno(int endPageno) {
this.endPageno = endPageno;
}
private String url;
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPrep() {
if(pageNo<=1){
prep=1;
}else{
prep=pageNo-1;
}
return prep;
}
public void setPrep(int prep) {
this.prep = prep;
}
public int getNextp() {
if(pageNo>=this.getTotalPage()){
nextp=this.getTotalPage();
}else{
//没有超出边界
nextp=pageNo+1;
}
return nextp;
}
public void setNextp(int nextp) {
this.nextp = nextp;
}
public int getTotalPage() {
if(totalRecordes%pageSize==0){
totalPage = totalRecordes/pageSize;
}else{
totalPage = totalRecordes/pageSize+1;
}
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalRecordes() {
return totalRecordes;
}
public void setTotalRecordes(int totalRecordes) {
this.totalRecordes = totalRecordes;
}
public List getRecordes() {
return recordes;
}
public void setRecordes(List recordes) {
this.recordes = recordes;
}
public int getStartIndex() {
startIndex = (pageNo-1)*pageSize;
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
标签:
原文地址:http://www.cnblogs.com/X-Ming/p/4525277.html