曹翔ID:java_xiang
15710次访问,排名7319(3)好友1人,关注者2
阿翔编程学
java_xiang的文章
原创 43 篇
翻译 0 篇
转载 7 篇
评论 8 篇
曹翔的公告
WebService,Java,J2EE 任何个人和单位均可免费复制,拷贝,复制时请注明出处。但如需商业用途或者使用,修改其中的全部或者部分代码,图片。请先和作者联系.
最近评论
asdf:很好,谢谢分享
xiang:恩,好吧,那句话怎么说的,反正就是帮人帮到底的意思吧。
丫头:这个多代码,别人找都难找,想想起他改良的办法啦,帮人帮到底么。。。。
xunmenglin:义愤填庸了~~~~
xunmenglin:我顶阿
楼主说得好啊
文章分类
收藏
    相册
    阿翔的相册
    Blog链接
    傻丫头的Blog
    冰冻小子的Blog
    大中华办公软件在线
    我的CSDN博客
    我的新浪Blog
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 阿翔编程学-Struts分页信息设置收藏

    新一篇: 阿翔编程学-Java Servlet验证码的输出 | 旧一篇: 阿翔编程学-Java缓存类的实现

    package com.jxsafe.source.common.applications.source.classinfo.pageinfo;

    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;

    import org.apache.commons.lang.builder.EqualsBuilder;
    import org.apache.commons.lang.builder.HashCodeBuilder;
    import org.apache.commons.lang.builder.ToStringBuilder;

    /**
     * 分页信息设置
     * @author CaoXiang
     */
    public class PageInformation implements Serializable, Cloneable {

      /**
       * The serialVersionUID
       */
      private static final long serialVersionUID = 7960850923665483933L;

      /**
       * Default span
       */
      protected static final int DEFAULT_SPAN = 10;

      /**
       * Page number (the first page is 1)
       */
      private int pageNo;

      /**
       * Page size
       */
      private int pageSize;

      /**
       * Count of total pages
       */
      private int totalPage;

      /**
       * Max record num;
       */
      private int maxRecordNum;

      /**
       * Creates a new <code>PageInformation</code> object.
       */
      public PageInformation() {
      }

      /**
       * Retrieves the pageNo.
       *
       * @return Returns the pageNo.
       */
      public int getPageNo() {
        return pageNo;
      }

      /**
       * Sets the pageNo to the given value.
       *
       * @param pageNo
       *          The pageNo to set.
       */
      public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
      }

      /**
       * Retrieves the pageSize.
       *
       * @return Returns the pageSize.
       */
      public int getPageSize() {
        return pageSize;
      }

      /**
       * Sets the pageSize to the given value.
       *
       * @param pageSize
       *          The pageSize to set.
       */
      public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
      }

      /**
       * Retrieves the totalPage.
       *
       * @return Returns the totalPage.
       */
      public int getTotalPage() {
        return totalPage;
      }

      /**
       * Sets the totalPage to the given value.
       *
       * @param totalPage
       *          The totalPage to set.
       */
      public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
      }

      /**
       * Reset method.
       */
      public void reset() {
        pageNo = 1;
        totalPage = 0;
      }

      /**
       * Retrieves the maxRecordNum.
       *
       * @return Returns the maxRecordNum.
       */
      public int getMaxRecordNum() {
        return maxRecordNum;
      }

      /**
       * Sets the maximum record number to the given value
       *
       * @param maxRecordNum
       */
      public void setMaxRecordNum(int maxRecordNum) {
        if (maxRecordNum < 0) {
          throw new IllegalArgumentException("Negative maxRecordNum!");
        } else {
          this.maxRecordNum = maxRecordNum;
          if (maxRecordNum == Integer.MAX_VALUE) {
            totalPage = 0x7fffffff;
          } else {
            totalPage = (maxRecordNum + pageSize - 1) / pageSize;
          }
          if (pageNo > totalPage) {
            pageNo = totalPage;
          }
        }
      }

      /**
       * Retrieves the offset (zero-based) of the first row of this page.
       *
       * @return the page data offset
       */
      public int getOffset() {
        return (pageNo - 1) * pageSize;
      }

      /**
       * Retrieves the default page span.
       *
       * @return the page numbers in the specified span
       */
      public List<Integer> getPageSpan() {
        return getPageSpan(DEFAULT_SPAN);
      }

      /**
       * Retrieves the page span.
       *
       * @param span
       *          the number of span of pages in either direction
       * @return the page numbers in the specified span
       */
      public List<Integer> getPageSpan(int span) {
        return getPageSpan(span, span);
      }

      /**
       * Retrieves the page span.
       *
       * @param leftSpan
       *          the number of span of the previous pages
       * @param rightSpan
       *          the number of span of the next pages
       * @return the page numbers in the specified span
       */
      public List<Integer> getPageSpan(int leftSpan, int rightSpan) {
        if (leftSpan <= 0) {
          throw new IllegalArgumentException("Left span must be positive!");
        }

        if (rightSpan <= 0) {
          throw new IllegalArgumentException("Right span must be positive!");
        }

        List<Integer> pages = new ArrayList<Integer>(leftSpan << 1);

        // Computes the start and end page number.
        int start = Math.max(pageNo - leftSpan, 1);
        int end = Math.min(pageNo + rightSpan, totalPage);

        for (int i = start; i <= end; i++) {
          pages.add(i);
        }

        return pages;
      }

      /**
       * Returns a hash code value for the object.
       *
       * @return a hash code value for this object.
       */
      @Override
      public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(371295, 137, this);
      }

      /**
       * Indicates whether some other object is "equal to" this one.
       *
       * @param obj
       *          the reference object with which to compare.
       * @return <code>true</code> if this object is the same as the obj argument;
       *         <code>false</code> otherwise.
       */
      @Override
      public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
      }

      /**
       * Retrieves a text representation for this object.
       *
       * @return the text representation
       */
      @Override
      public String toString() {
        return ToStringBuilder.reflectionToString(this);
      }

    发表于 @ 2007年05月31日 14:49:00|评论(loading...)|编辑

    新一篇: 阿翔编程学-Java Servlet验证码的输出 | 旧一篇: 阿翔编程学-Java缓存类的实现

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 曹翔