📄 mypages.java
字号:
package com.softeem.util;
import java.util.ArrayList;
import java.util.List;
public class MyPages {
@SuppressWarnings("unchecked")
private List pages; // 总记录集合
private int recordNum; // 总记录数
private int pageCount; // 页面总数
private int pageSize; // 每页记录数
private int pageNum; // 页码
private String pageName; // 页面名称
private String pageNumLink; // 每页链接字符串
private String prevPageLink; // 上一页链接
private String nextPageLink; // 下一页链接
private String allPageLink; // 所有的链接
@SuppressWarnings("unchecked")
public MyPages(List infos, String pageName, int pageSize,int recordNum, int pageNum) {
this.initial(infos, pageName, pageSize,recordNum, pageNum);
}
@SuppressWarnings("unchecked")
private void initial(List infos, String pageName,int pageSize, int recordNum, int pageNum) {
List list = null;
if (infos == null) {
list = new ArrayList();
} else {
list = infos;
}
this.pageName = pageName;
this.pageSize = pageSize;
this.recordNum = recordNum;
this.pageNum = pageNum;
this.setPageCount();
this.setPages(list);
this.setPageNumLink();
this.setPrevPageLink();
this.setNextPageLink();
this.setAllPageLink();
}
public int getPageCount() {
return this.pageCount;
}
public int getPageSize() {
return this.pageSize;
}
public int getPageNum() {
return this.pageNum;
}
public int getRecordNum() {
return this.recordNum;
}
@SuppressWarnings("unchecked")
public List getPages() {
return this.pages;
}
public String getPageNumLink() {
return this.pageNumLink;
}
public String getPrevPageLink() {
return this.prevPageLink;
}
public String getNextPageLink() {
return this.nextPageLink;
}
public String getAllPageLink() {
return this.allPageLink;
}
private void setPageNumLink() {
String strLinks = "";
if (this.pageCount > 1) {
if(this.pageCount<=10)
{
for (int i = 1; i <= this.pageCount; ++i) {
if (i == this.pageNum) {
strLinks += "<b>" + i + "</b> ";
} else {
strLinks += "[<a href=\"" + this.pageName + "?pageNum=" + i
+ "\">" + i + "</a>] ";
}
}
}else
{
StringBuffer sb = new StringBuffer("<select onchange=window.location='"+this.pageName+"?pageNum='"+"+(this.selectedIndex+1)"+">");
for (int i = 1; i <= this.pageCount; ++i) {
if(i==pageNum)
{
sb.append("<option value="+i+" selected>"+i+"</option>");
}else
{
sb.append("<option value="+i+">"+i+"</option>");
}
}
sb.append("</select>");
strLinks = sb.toString();
}
}
this.pageNumLink = strLinks;
}
private void setPrevPageLink() {
String strLinks = "";
int prevPageNum = this.pageNum - 1;
if (prevPageNum >= 1)
strLinks = "<a href=\"" + this.pageName + "?pageNum=" + prevPageNum
+ "\">上一页</a>";
else
strLinks = " ";
this.prevPageLink = strLinks;
}
private void setNextPageLink() {
String strLinks = "";
int nextPageNum = this.pageNum + 1;
if (nextPageNum <= this.pageCount)
strLinks = "<a href=\"" + this.pageName + "?pageNum=" + nextPageNum
+ "\">下一页</a>";
else
strLinks = " ";
this.nextPageLink = strLinks;
}
private void setAllPageLink() {
this.allPageLink = this.prevPageLink + " "
+ this.pageNumLink + " " + this.nextPageLink
+ " " + +this.pageNum + "/"
+ this.pageCount + "页 " + "共"
+ this.recordNum + "条";
}
@SuppressWarnings("unchecked")
private void setPages(List infos) {
this.pages = infos;
}
public void setPageCount() {
System.out.println("recordNum:>>>>>>"+recordNum);
this.pageCount = (recordNum+pageSize-1)/pageSize;
System.out.println("pageCount:>>>>"+pageCount);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -