分页思想

分页主要分为两种,即伪分页和真分页

伪分页:将符合查询条件的数据一次性从数据库中查询出来,并加载到前端页面的table中,通过选择性展示来控制分页。

真分页:将需要展示的页码以及行数传给服务器,在sql查询指定的记录范围。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package org.wzj.common; import java.io.IOException; import java.net.URLDecoder; import java.net.URLEncoder; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTagSupport; public class FenyeTag extends BodyTagSupport { private static final long serialVersionUID = 1L; private String html; private String exname; private String target = ""; //链接所响应的框架窗口 private String cssClass; //样式名 private String action; //链接 private Integer pageCount; //总页数 private Integer current; //当前页码 private Integer showCount = 10; //在页面上显示多少个链接 private Integer spanWidth = 50; public static final String TEXT = "background-color:blue;color:white;"; public int doEndTag(){ BodyContent body = this.getBodyContent(); JspWriter out = body.getEnclosingWriter(); html = "<div id='fydiv'>"; int start = 1; if ( pageCount > 0 ){ if ( current > pageCount ){ current = pageCount; } if ( current < 1 ){ current = 1; } if ( exname == null || exname.equals("")){ html += "<a href='" + action + "?pageNum=1' target='" + target + "' class='" + cssClass + "' }else{ html += "a href=' target='" + target + "' class='" + cssClass + "' } html += "'>首页</a>"; if ( current > showCount - showCount/3 ){ start = start + showCount/3*(current/(showCount/3)-2); } if ( current < showCount - showCount/3 ){ start = 1; } int rcount = 1; //////////////////////////// for ( int i = 1; i <= pageCount; i ++ ){ if ( i >= start ){ //起始页码 if ( rcount <= showCount ){ //只显示showCount个链接 if ( exname == null || exname.equals("")){ html += "  <a href='" + action + "?pageNum=" + i + "' target='" + target + "' class='" + cssClass + "' }else{ html += "  a href=' target='" + target + "' class='" + cssClass + "' } if ( current == i ){ html += TEXT; } html += "'>" + i + "</a>  "; } if ( i < pageCount && rcount == showCount ){ html += "...  "; } rcount ++; } } //////////////////////////// if ( exname == null || exname.equals("")){ html += "<a href='" + action + "?pageNum=" + pageCount + "' target='" + target + "' class='" + cssClass + "' }else{ html += "a href=' target='" + target + "' class='" + cssClass + "' } html += "'>末页</a>"; html += "    第<span + current + "</span>页 共<span + pageCount + "</span>页"; } html += "</div>"; try { out.print(html); out.flush(); body.clearBody(); } catch (IOException ex) { ex.printStackTrace(); } return this.EVAL_PAGE; } public String getExname() { return exname; } public void setExname(String exname) { this.exname = exname; } public String getTarget() { return target; } public void setTarget(String target) { this.target = target; } public String getCssClass() { return cssClass; } public void setCssClass(String cssClass) { this.cssClass = cssClass; } public String getAction() { return action; } public void setAction(String action) { this.action = action; } public Integer getPageCount() { return pageCount; } public void setPageCount(Integer pageCount) { this.pageCount = pageCount; } public Integer getCurrent() { return current; } public void setCurrent(Integer current) { this.current = current; } public Integer getShowCount() { return showCount; } public void setShowCount(Integer showCount) { this.showCount = showCount; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值