'jsp pagging'에 해당되는 글 1건

  1. 2010/02/10 visualp jsp pagging class

jsp pagging class

JSP, JAVA RSS Icon ATOM Icon 2010/02/10 13:57 visualp
[원문]http://lovelovewoo.springnote.com/pages/5055397
package board.util;
  • public class Paging {
  •  private int totalRows = 0;
     private int currentPage = 1;
     private int pageSize = 10;
     private int blockSize = 10;
     private int totalPages;
     private int totalBlocks;
     private int startPageNum;
     private int endPageNum;
     private int currentBlock;
  •  private String amp = "";
     
     // for design
     private String firstLink = "[<<]";
     private String firstOffLink = "";
     private String prevLink = "[<]";
     private String prevOffLink = "";
     private String nextLink = "[>]";
     private String nextOffLink = "";
     private String lastLink = "[>>]";
     private String lastOffLink = "";
     
     private String delimiter = "|";
     
     // current Page Wrapper
     private String preWrap = "<b>";
     private String postWrap = "</b>";
     
     private String linkPage = "";
     private String queryString = "";

  •  private int start,end;
     
     
     
     
  •  public int getStart() {
      return start;
     }
  •  public void setStart(int start) {
      this.start = start;
     }
  •  public int getEnd() {
      return end;
     }
  •  public void setEnd(int end) {
      this.end = end;
     }
  •  public String getFirstLink() {
      return firstLink;
     }
  •  public void setFirstLink(String firstLink) {
      this.firstLink = firstLink;
     }
  •  public String getFirstOffLink() {
      return firstOffLink;
     }
  •  public void setFirstOffLink(String firstOffLink) {
      this.firstOffLink = firstOffLink;
     }
  •  public String getPrevLink() {
      return prevLink;
     }
  •  public void setPrevLink(String prevLink) {
      this.prevLink = prevLink;
     }
  •  public String getPrevOffLink() {
      return prevOffLink;
     }
  •  public void setPrevOffLink(String prevOffLink) {
      this.prevOffLink = prevOffLink;
     }
  •  public String getNextLink() {
      return nextLink;
     }
  •  public void setNextLink(String nextLink) {
      this.nextLink = nextLink;
     }
  •  public String getNextOffLink() {
      return nextOffLink;
     }
  •  public void setNextOffLink(String nextOffLink) {
      this.nextOffLink = nextOffLink;
     }
  •  public String getLastLink() {
      return lastLink;
     }
  •  public void setLastLink(String lastLink) {
      this.lastLink = lastLink;
     }
  •  public String getLastOffLink() {
      return lastOffLink;
     }
  •  public void setLastOffLink(String lastOffLink) {
      this.lastOffLink = lastOffLink;
     }
  •  public String getDelimiter() {
      return delimiter;
     }
  •  public void setDelimiter(String delimiter) {
      this.delimiter = delimiter;
     }
  •  public String getPreWrap() {
      return preWrap;
     }
  •  public void setPreWrap(String preWrap) {
      this.preWrap = preWrap;
     }
  •  public String getPostWrap() {
      return postWrap;
     }
  •  public void setPostWrap(String postWrap) {
      this.postWrap = postWrap;
     }
  •  public String getLinkPage() {
      return linkPage;
     }
  •  public void setLinkPage(String linkPage) {
      this.linkPage = linkPage;
     }
  •  public String getQueryString() {
      return queryString;
     }
  •  public void setQueryString(String queryString) {
      this.queryString = queryString;
     }
  •  // result temp object
     public StringBuffer pageString = new StringBuffer();
     
     public Paging(int currentPage , int pageSize , int blockSize , int totalRows)
     {
      this.currentPage = currentPage;
      this.pageSize = pageSize;
      this.blockSize = blockSize;
      this.totalRows = totalRows;
     
      initialize();
     }
     
     public void initialize()
     {
      this.totalPages = (int)Math.ceil((double)this.totalRows / this.pageSize);
      this.totalBlocks = (int)Math.ceil((double)this.totalPages / this.blockSize);
      this.currentBlock = (int)Math.ceil((double)((this.currentPage - 1) / this.blockSize)) + 1;  
      this.startPageNum = ((this.currentBlock - 1) * this.pageSize) + 1;
      this.endPageNum = this.startPageNum + this.pageSize;
      this.start = (currentPage-1)*pageSize+1;
      this.end = start+pageSize-1;
     }
     
     public void prePrint()
     {
      // set first block link
      if(this.currentBlock > 1)
       pageString.append("<a href=\"" + this.linkPage + "?" + this.queryString + this.amp + "page=" + (((this.currentBlock - 2) * this.pageSize) + 1) + "\">" + this.firstLink + "</a> ");
      else
       pageString.append(this.firstOffLink + " ");
       
     
      // set prev page link
      if(this.currentPage > 1)
       pageString.append("<a href=\"" + this.linkPage + "?" + this.queryString + this.amp + "page=" + (this.currentPage  - 1) + "\">" + this.prevLink + "</a> ");
      else
       pageString.append(this.prevOffLink + " ");  
     }
     
     public void postPrint()
     {
      // set next page link
      if(this.currentPage < this.totalPages )
       pageString.append("<a href=\"" + this.linkPage + "?" + this.queryString + this.amp + "page=" + (this.currentPage + 1) + "\">" + this.nextLink + "</a> ");
      else
       pageString.append(this.nextOffLink + " ");
     
      // set last page link
      if(this.currentBlock < this.totalBlocks)
       pageString.append("<a href=\"" + this.linkPage + "?" + this.queryString + this.amp + "page=" + ((this.currentBlock * this.pageSize) + 1) + "\">" + this.lastLink + "</a> ");
      else
       pageString.append(this.lastOffLink);
     }
     
     public void printList()
     {
      for(int i = startPageNum ; i <= endPageNum ; i++)
      {
       if(i > this.totalPages || i == endPageNum)
        break;
       else if(i > startPageNum)
        pageString.append(this.delimiter);
       
       if(i == this.currentPage)  
        pageString.append(" " + this.preWrap + i +  this.postWrap + " ");
       else
        pageString.append(" <a href=\"" + this.linkPage + "?" + this.queryString + this.amp + "page=" + i + "\">" + i + "</a> ");
      }
     }
     
     public String print()
     {
      // set amp if already to set up queryString property
      if(!this.queryString.equals(""))
       this.amp = "&";
     
      if(this.totalPages > 1)
      {
       this.prePrint();
       this.printList();
       this.postPrint();
      }
     
      return(pageString.toString());
     }
     
     /**
      * @param args
      */
     /*
     public static void main(String[] args) {
     
      // TODO Auto-generated method stub
      Pagination page = new Pagination(1 , 10, 10 , 11);
      page.linkPage = "pagenum.jsp";
      page.queryString = "param1=test&param2=test2";
     
      // for design
      page.firstLink = "<img src=\"/first.gif\">";
      page.prevLink = "<img src=\"/prev.gif\">";
      page.nextLink = "<img src=\"/next.gif\">";
      page.lastLink = "<img src=\"/last.gif\">";
     
      page.firstOffLink = "[<<]";
      page.prevOffLink = "[<]";
      page.nextOffLink = "[>]";
      page.lastOffLink = "[>>]";
     
      page.delimiter = "||";
     
     
      //print
      System.out.println(page.print());
     }
     */
  • }
  • 2010/02/10 13:57 2010/02/10 13:57
    받은 트랙백이 없고, 댓글이 없습니다.

    댓글+트랙백 RSS :: http://blog.visualp.com/rss/response/198

    댓글+트랙백 ATOM :: http://blog.visualp.com/atom/response/198