com.power.common.model.PageVo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-util Show documentation
Show all versions of common-util Show documentation
ApplicationPower common-util
package com.power.common.model;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.List;
/**
* 主要用于前端内容展示分页,分页链接由后台输出
* PageVo根据自定义的url直接生成链接,messageFormat占位替换生成页码
* USAGE:
* RequestMapping(value="news/p{pageIndex}.htm",method = RequestMethod.GET)
* public String list(@PathVariable int pageIndex,Model model){
* try{
* PageVo pageDto = this.newsService.getPage(0,pageIndex,12);
* pageDto.setUrl("news/p{0}.htm");
* model.addAttribute("list",pageDto);
* }catch (Exception e){
* return "";
* }
* return "forward:/news.jsp";
*}
* @author sunyu
* @param Generics
*/
public class PageVo implements Serializable {
private static final long serialVersionUID = 1923401118856169487L;
private Long total;//total record
private String url;//使用messageFormat占位替换
private Integer pageIndex;// 页码,当前页数
private Integer pageSize;// 分页条数
private List items;// 查询结果
private int displayEntries = 5;//连续分页主体部分显示的分页条目数
private int edgeEntries = 1;//两侧显示的首尾分页的条目数
//default
public PageVo() {
super();
}
public PageVo(Long total, Integer pageIndex, Integer pageSize, List items) {
super();
this.total = total;
this.pageIndex = pageIndex;
this.pageSize = pageSize;
this.items = items;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public Integer getPageIndex() {
return pageIndex;
}
public void setPageIndex(Integer pageIndex) {
this.pageIndex = pageIndex;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
@Override
public String toString() {
return "PageVo [total=" + total + ", pageIndex=" + pageIndex
+ ", pageSize=" + pageSize + ", items=" + items + "]";
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getNavigation(){
Integer totalPage = (int) (total % pageSize > 0 ? (total
/ pageSize + 1) : (total / pageSize));
//From jQuery pagination
//int ne_half = ((displayEntries&1)==1)?(displayEntries/2+1):displayEntries/2;
int ne_half = ((displayEntries&1)==1)?(displayEntries>>1)+1:displayEntries>>1;
int upper_limit = totalPage-displayEntries;
pageIndex = (pageIndex<1)?1:pageIndex;
int currentPage = pageIndex -1;
int start = currentPage>ne_half?Math.max(Math.min(currentPage-ne_half, upper_limit), 0):0;
int end = currentPage>ne_half?Math.min(currentPage+ne_half,totalPage):Math.min(displayEntries,totalPage);
StringBuffer buffer = new StringBuffer();
buffer.append("");
// Generate "Previous"-Link
if(pageIndex==1||totalPage==0){
buffer.append("上一页");
}else{
String str = MessageFormat.format("上一页");
}
// Generate starting points
if(start>0&&edgeEntries>0){
int end1 = Math.min(edgeEntries, start);
for(int i=0; i").append(i+1).append("");
}
if(edgeEntries < start) {
buffer.append("...");
}
}
// Generate interval links
for(int i= start; i").append(i+1).append("");
}else{
String str = MessageFormat.format("").append(i+1).append("");
}
}
// Generate ending points
if (end < totalPage &&edgeEntries > 0) {
if(totalPage-edgeEntries > end) {
buffer.append("...");
}
int begin = Math.max(totalPage-edgeEntries, end);
for(int i=begin; i").append(i+1).append("");
}
}
// Generate "Next"-Link
if(pageIndex == totalPage || totalPage == 0){
buffer.append("下一页");
}else{
String str = MessageFormat.format("下一页");
}
buffer.append(" ");
return buffer.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy