分页
来源:互联网 发布:oss js 上传文件 跨域 编辑:程序博客网 时间:2024/05/01 22:48
package com.li.utils;
public class PageIndex {
private long startindex;
private long endindex;
public PageIndex(long startindex, long endindex) {
this.startindex = startindex;
this.endindex = endindex;
}
public long getStartindex() {
return startindex;
}
public void setStartindex(long startindex) {
this.startindex = startindex;
}
public long getEndindex() {
return endindex;
}
public void setEndindex(long endindex) {
this.endindex = endindex;
}
public static PageIndex getPageIndex(long viewpagecount, int currentPage, long totalpage){
long startpage = currentPage-(viewpagecount%2==0? viewpagecount/2-1 : viewpagecount/2);
long endpage = currentPage+viewpagecount/2;
if(startpage<1){
startpage = 1;
if(totalpage>=viewpagecount) endpage = viewpagecount;
else endpage = totalpage;
}
if(endpage>totalpage){
endpage = totalpage;
if((endpage-viewpagecount)>0) startpage = endpage-viewpagecount+1;
else startpage = 1;
}
return new PageIndex(startpage, endpage);
}
}
package com.li.bean.service.base;
import java.util.List;
import com.li.utils.PageIndex;
public class Paging<T> {
private List<T> pageList;
private long totalRecords;
private long totalPage;
private int currentPage = 1;
private int maxResult = 12;
private PageIndex pageIndex;
// 分页条上现实的页数
private int countPage= 5;
public void setPageModel(PageModel<T> pageModel) {
if (pageModel != null) {
this.pageList = pageModel.getPageList();
this.totalRecords = pageModel.getTotalrecordNo();
this.totalPage = (totalRecords % maxResult == 0) ? totalRecords
/ maxResult : (totalRecords / maxResult) + 1;
this.pageIndex = PageIndex.getPageIndex(countPage,this.currentPage, totalPage);
}
}
public long getTotalPage() {
return totalPage;
}
public List<T> getPageList() {
return pageList;
}
public int getCurrentPage() {
return currentPage < 1 ? 1 : this.currentPage;
}
public void setCurrentPage(int currentPage) {
if (currentPage > 0) {
this.currentPage = currentPage;
} else {
currentPage = 1;
}
}
public int getMaxResult() {
return maxResult;
}
public long getFirstIndex() {
return (this.currentPage - 1) * this.maxResult;
}
public PageIndex getPageIndex() {
return pageIndex;
}
public Paging() {
System.out.println("新建个Paging 对象");
}
}
@Override
public String execute() throws Exception {
PageModel<ProductType> pageModel = productTypeService.getPageData(
ProductType.class, (int) paging.getFirstIndex(), paging .getMaxResult());
this.paging.setPageModel(pageModel);
HttpServletRequest request =ServletActionContext.getRequest();
request.setAttribute("paging", paging);
return "success";
}
<c:forEach begin="${paging.pageIndex.startindex}"
end="${paging.pageIndex.endindex}" var="wp">
<c:if test="${paging.currentPage==wp}">
<b>第${wp}页</b>
</c:if>
<c:if test="${paging.currentPage!=wp}">
<a href="product_typelist.action?paging.currentPage=${wp}"
class="a03">第${wp}页</a>
</c:if>
</c:forEach>
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- 分页
- CSDN特别收录 --- 超强的指针 *一辈子都找不到的牛B贴
- 解决jquery和其他库的冲突
- 将gridview中的数据导出到excel中
- ORACLE之TO_DATE
- vc海量数据树控件使用总结
- 分页
- The current identity (NT AUTHORITY/NETWORK SERVICE) does not have write access to 'C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319
- 网络程序员须知
- 10.11.4-----iOS出4.2了.
- 书目
- oracle11g客户端-配置
- Web前端-HTTP Cache-control
- 郁闷转晴
- android另一种访问包资源方式