📄 pages.java
字号:
package com.caolulu.assh.comm;
import java.util.Locale;
import org.apache.commons.lang.builder.ToStringBuilder;
public class Pages {
String filename = ""; //文件吿
int page = 1; //页号
long totals = -1; //记录总数
int perpagenum = 20; //每页显示记录敿
int style = 0; //分页字串样式
int allpage = 1; //总页敿
int cpage = 1; //当前顿
int spage = 1; //弿始记录数
String listPageBreak = "";
String[] pagesign = null;
Locale locale = Locale.getDefault();
public Pages() {
this.pagesign = this.getPagesign();
}
public Pages(Locale locale) {
this.locale = locale;
this.pagesign = this.getPagesign();
}
public String getFileName() {
return this.filename;
}
public void setFileName(String aFileName) {
this.filename = aFileName;
}
public int getPage() {
return this.page;
}
public void setPage(int aPage) {
if (aPage < 1) {
this.page = 1;
}
this.page = aPage;
}
public long getTotals() {
return this.totals;
}
public void setTotals(long aTotals) {
this.totals = aTotals;
}
public int getPerPageNum() {
return this.perpagenum;
}
public void setPerPageNum(int aperpagenum) {
this.perpagenum = aperpagenum;
}
public int getStyle() {
return this.style;
}
public void setStyle(int aStyle) {
this.style = aStyle;
}
public void setPagesign(String[] apagesign) {
this.pagesign = apagesign;
}
public int getSpage() {
return this.spage;
}
public void doPageBreak() {
this.allpage = (int) Math.ceil( (this.totals + this.perpagenum - 1) /
this.perpagenum);
int intPage = this.page;
if (intPage > this.allpage) { // pages == 0
this.cpage = 1;
}
else {
this.cpage = intPage;
}
this.spage = (this.cpage - 1) * this.perpagenum;
getPageBreakStr();
}
public String getListPageBreak() {
return this.listPageBreak;
}
private void getPageBreakStr() {
//System.out.println(filename + " " + filename.endsWith(Constant.FILEPREFIX));
if (this.filename.indexOf("?") == -1 &&
(this.filename.endsWith(".do"))) {
//System.out.println("---------");
this.filename = this.filename + "?";
}
else {
if (!this.filename.endsWith("&")) {
this.filename = this.filename + "&";
}
}
StringBuffer sb = new StringBuffer();
//------------------6
if (this.style == 6) {
//丿行显示页敿
int pagesep = 5;
//总行敿
int allpagesep = (int) Math.ceil( (allpage + pagesep - 1) / pagesep);
//当前行数
int cpagesep = (int) Math.ceil( (cpage + pagesep - 1) / pagesep);
//当前丿行显示页敿
int cnum;
if (allpage > 0) {
//在页丿
if (cpagesep != allpagesep) {
cnum = pagesep;
}
//页末
else {
cnum = allpage % pagesep;
//正好整除
if (cnum == 0) {
cnum = pagesep;
}
}
}
else {
cnum = 0;
}
System.out.println("cpage:" + cpage + " cpagesep:" + cpagesep + " allpagesep:" + allpagesep);
/**
* previous butten ,append to
* <a href='xxx.lt?page=x&t=x'><img></a>
*/
sb.append("<a href='");
sb.append("javascript:loadMessagesList(");
//徿前一衿
int previous;
if (cpage <= 1) {
previous = 1;
}
else {
previous = cpage - 1;
}
sb.append(previous);
sb.append(");'>");
sb.append(Constant.MESSAGE.getMessage(this.locale,
"comm.pages.previous"));
sb.append("</a>");
/**
* middle butten ,append to
* <a href='xxx.lt?page=x&t=x'><img></a>
*/
for (int i = 0; i < cnum; i++) {
sb.append(" <span class='kk2'><a href='");
sb.append("javascript:loadMessagesList(");
sb.append( ( (i + 1) + ( (cpagesep - 1) * pagesep)));
sb.append(");'>");
if (cpage == (i + 1) + ( (cpagesep - 1) * pagesep)) {
sb.append("<font color='red'>" + ( (i + 1) + ( (cpagesep - 1) * pagesep)) + "</font>");
}
else {
sb.append( ( (i + 1) + ( (cpagesep - 1) * pagesep)));
}
sb.append("</a></span>");
}
/**
* next butten ,append to
* <a href='xxx.lt?page=x&t=x'><img></a>
*/
sb.append(" <a href='");
sb.append("javascript:loadMessagesList(");
int next;
if (cpage >= allpage) {
next = (int) allpage;
}
else {
next = cpage + 1;
}
sb.append(next);
sb.append(");'>");
sb.append(Constant.MESSAGE.getMessage(this.locale,
"comm.pages.next"));
sb.append("</a> ");
int _cpage = 0;
if (this.allpage == 0) {
_cpage = 0;
}
else {
_cpage = cpage;
}
this.listPageBreak = sb.toString();
return;
}
//-------------------6
}
public String[] getPagesign() {
String[] pagessign = {
Constant.MESSAGE.getMessage(this.locale, "comm.pages.first"),
Constant.MESSAGE.getMessage(this.locale, "comm.pages.previous"),
Constant.MESSAGE.getMessage(this.locale, "comm.pages.next"),
Constant.MESSAGE.getMessage(this.locale, "comm.pages.end")};
return pagessign;
}
public static void main(String args[]) {
int allpagesep = (int) 1 % 2;
int cpage = 1;
int pagesep = 2;
System.out.println(Math.ceil( (1 + 5 - 1) / 5));
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return new ToStringBuilder(this).append("pagesign", this.pagesign)
.append("page", this.page).append("listPageBreak",
this.listPageBreak).append("perPageNum",
this.getPerPageNum()).append("spage", this.spage)
.append("totals", this.totals).append("fileName",
this.getFileName()).append("style", this.style)
.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -