📄 advancedpagination.java
字号:
package tarena.data;
import java.util.LinkedList;
import java.util.List;
/**
* 高级分页类,考虑到当分页结果过多时,给分页的结果再次进行分页。
*/
public class AdvancedPagination extends SimplePagination {
//允许同时显示的最大的页面数,默认为10
private int maxshow = 10;
//要显示的分页集合
private List<Page> pages = null;
public AdvancedPagination() {}
/**
* @param total 结果集中的总记录数
* @param every 每页要显示的个数
* @param current 当前第几页
* @param maxshow 分页最多显示几页
* @param url 分页链接
* @param param 分页信息在链接中的参数名称
*/
public AdvancedPagination(int total, int every, int current, int maxshow, String url, String param) {
super(total, every, current, url, param);
this.setMaxshow(maxshow);
}
/**
* @param total 结果集中的总记录数
* @param every 每页要显示的个数
* @param current 当前第几页
* @param maxshow 分页最多显示几页
* @param url 分页链接
*/
public AdvancedPagination(int total, int every, int current, int maxshow, String url) {
super(total, every, current, url);
this.setMaxshow(maxshow);
}
public int getMaxshow() {
return maxshow;
}
public void setMaxshow(int maxshow) {
this.maxshow = maxshow>0?maxshow:this.maxshow;
}
@Override
public int getTotal() {
return super.getTotal();
}
@Override
public List<Page> getContent() {
List<Page> content = null;
try {
if(this.pages != null) return this.pages;
content = new LinkedList<Page>();
int current = this.getCurrent();
int half = this.maxshow%2==0?this.maxshow/2:this.maxshow/2+1;
int totalpage = this.getTotalPage();
int start = current - half + 1;
int end = start + this.maxshow -1;
//如果要显示的页面超出下限,显示前maxshow 页
if(start<=1){
start = 1;
end = this.maxshow>totalpage?totalpage:this.maxshow;
}
//如果要显示的页面超出上限,显示后maxshow 页
if(end>=totalpage){
start = (totalpage - this.maxshow + 1)<1?1:(totalpage - this.maxshow + 1);
end = totalpage;
}
for(int i=start;i<=end;i++){
content.add(new Page(i,this.getURLByPage(i)));
}
if(this.getCurrent() - start < content.size()){
content.get(this.getCurrent()-start).setUrl(null);
}
} catch (RuntimeException e) {
e.printStackTrace();
}
return content;
}
public Page getNext() {
return super.getNext(null);
}
public Page getPrevious() {
return super.getPrevious(null);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -