📄 pageinfo.java
字号:
package org.pontifex.web.mapping;
import java.util.List;
import java.util.ArrayList;
/**
* Created by IntelliJ IDEA.
* User: Songzou
* Date: 2007-4-8
* Time: 11:03:06
*
* 分页mapping
*/
public class PageInfo extends LoginUser{
private static final long serialVersionUID = 7873852623469564487L;
private long totalRows = 0;//总的记录数 如:共100条记录
private List pageList = new ArrayList(0);
private int startIndex = 0; //当前页面第一条记录数
private int currentPage = 1; //当前页面 如:当前第1页
private int totalPages = 1; //总的页面数 如:共10页
private int perPageRows = 15;//每一页显示的记录数 (可以通过set方法来进行修改)
private String html ; //分页查询按钮
//是不是实现分页
private boolean showPages = true;
public final int getCurrentPage() {
return currentPage;
}
public final void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public final int getPerPageRows() {
return perPageRows;
}
public final void setPerPageRows(int perPageRows) {
if(perPageRows>0)
this.perPageRows = perPageRows;
}
public final boolean isShowPages() {
return showPages;
}
public final void setShowPages(boolean showPages) {
this.showPages = showPages;
}
public final int getTotalPages() {
return totalPages;
}
public final void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public final long getTotalRows() {
return totalRows;
}
public final void setTotalRows(long totalRows) {
this.totalRows = totalRows;
//计算出现在的总的页数
this.totalPages = (int) Math.ceil((this.totalRows - 1) / this.perPageRows) + 1;
if (this.currentPage > this.totalPages) {
this.currentPage = 1;
}
}
public final List getPageList() {
return pageList;
}
public final void setPageList(List pageList) {
this.pageList = pageList;
}
public final int getStartIndex() {
this.setStartIndex((currentPage-1)*perPageRows);
return startIndex;
}
private void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
/**
*
* @return 分页查询按钮
*/
public final String getHtml(){
if(!showPages)return " ";
StringBuffer string=new StringBuffer();
string.append("<script>\n");
string.append("function go(num){\n");
string.append(" var pageform = window.document.getElementById('pageform');\n");
string.append(" pageform.action=pageform.action+'¤tPage='+num;\n");
string.append(" pageform.submit();\n");
string.append("}\n");
string.append("function goto(thisPage,totalPage){\n");
string.append(" var gotoPageObject = window.document.getElementById('gotoPage');\n");
string.append(" var gotoPage = gotoPageObject.value ;\n");
string.append(" if(isNaN(gotoPage)){\n");
string.append(" gotoPageObject.focus();\n") ;
string.append(" alert('你输入的页码有误请重新输入!');\n");
string.append(" gotoPageObject.value=1;\n");
string.append(" return ; \n");
string.append(" }\n");
string.append(" if(gotoPage==thisPage){\n");
string.append(" alert('已经是当前页!');\n");
string.append(" return ;\n");
string.append(" }\n");
string.append(" if(gotoPage<1||gotoPage>totalPage){\n");
string.append(" gotoPageObject.focus();\n") ;
string.append(" alert('不存在该页码!');\n");
string.append(" gotoPageObject.value=1;\n");
string.append(" return ; \n");
string.append(" }\n");
string.append(" go(gotoPage);\n");
string.append("}\n");
string.append("</script>\n");
//当前为第一页
if(currentPage==1){
string.append("<input type='button' class='btn' style='width:50px;' value='首 页' disabled/> ");
string.append("<input type='button' class='btn' style='width:50px;' value='上一页' disabled/> ");
}else{
string.append("<input type='button' class='btn' style='width:50px;' value='首 页' onClick='go(1);' /> ");
string.append("<input type='button' class='btn' style='width:50px;' value='上一页' onClick='go(");
string.append(currentPage-1);
string.append(")'/> ");
}
//当前为最后一页
if(currentPage==totalPages){
string.append("<input type='button' class='btn' style='width:50px;' value='下一页' disabled/> ");
string.append("<input type='button' class='btn' style='width:50px;' value='尾 页' disabled/> ");
}else{
string.append("<input type='button' class='btn' style='width:50px;' value='下一页' onClick='go(");
string.append(currentPage+1);
string.append(")'/> ");
string.append("<input type='button' class='btn' style='width:50px;' value='尾 页' onClick='go(");
string.append(totalPages);
string.append(")'/> ");
}
string.append(" ");
string.append("<input type='text' id='gotoPage' class='int' value='");
string.append(currentPage);
string.append("' style='width:30px;'/> <input type='button' class='btn' style='width:30px;' value='GO' onClick='goto(");
string.append(currentPage);
string.append(",");
string.append(totalPages);
string.append(")'/>") ;
string.append(" 当前第");
string.append(currentPage);
string.append("页/共");
string.append(totalPages);
string.append("页 每页");
string.append(perPageRows);
string.append("条记录 总共记录数");
string.append(totalRows);
string.append("条 ");
setHtml(string.toString());
return html;
}
private void setHtml(String html) {
this.html = html;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -