waysun一路阳光

不轻易服输,不轻言放弃.--心是梦的舞台,心有多大,舞台有多大。踏踏实实做事,认认真真做人。

  BlogJava :: 首页 :: 新随笔 :: 联系 ::  :: 管理 ::
  167 随笔 :: 1 文章 :: 64 评论 :: 0 Trackbacks
1.action

public class DataMangAction extends ActionSupport implements ServletRequestAware, ModelDriven<DataMangForm>
{
   private String str;
   private HttpServletRequest request;
   private int pageSize = 2;
   private DataMangForm model = new DataMangForm();
  
  public String execute() throws Exception
  {
   System.out.println("ok");
   str="execute";
   return str;
  }
  public String init() throws Exception
  {
   DataMangForm dataMangForm = getModel();
         ArrayList baseInfoList;
         // 获取当前页码
         int pageNum = dataMangForm.getPageNum();
         DataMangOpertion dataMangOpertion=new DataMangOpertion();
         baseInfoList = dataMangOpertion.getAllBaseInfo(pageSize, pageNum);
         if (baseInfoList != null)
         {
          dataMangForm.setBaseInfoList(baseInfoList);
             Pagination pagination = dataMangOpertion.getPageInAction();
            
          pagination.setShowCurrentState(true);
          pagination.setShowPageNumber("dataMangAction!init.action", "", 10, 5);
          dataMangForm.setPagination(pagination);
          request.setAttribute("pagination", pagination);
         }
 
   str="init";
   return str;
  }
  public String toAdd() throws Exception
  {
   str="toAdd";
   return str;
  }
     public DataMangForm getModel()
  {
   return model;
  }

     public void setServletRequest(HttpServletRequest request)
     {
     this.request = request;
     }
}
2.pagination

public class Pagination
{

  /*
  ** pageSize      每页记录数
  ** recordCount   总记录数
  ** pageNum       当前页
  ** pageCount     总页数
  */
  private int pageSize;
  private int recordCount;
  private int pageNum;
  private int pageCount;
  private String showPageNumber="";
  private String showCurrentState;

  public Pagination()
  {
  }
  public Pagination(int pageNum,int pageSize,int recordCount,int pageCount)
  {
    this.setPageNum(pageNum);
    this.setPageSize(pageSize);
    this.setRecordCount(recordCount);
    this.setPageCount(pageCount);
  }
  public void setPageSize(int pageSize)
  {
    this.pageSize=pageSize;
  }
  public int getPageSize()
  {
    return pageSize;
  }
  public void setRecordCount(int recordCount)
  {
    this.recordCount=recordCount;
  }
  public int getRecordCount()
  {
    return recordCount;
  }
  public void setPageNum(int pageNum)
  {
    this.pageNum=pageNum;
  }
  public int getPageNum()
  {
    return pageNum;
  }
  public void setPageCount(int pageCount)
  {
    this.pageCount=pageCount;
  }
  public int getPageCount()
  {
    return pageCount;
  }
  //显示分页的当前状态信息
  public void setShowCurrentState(boolean bool)
  {
    if(bool)
    {
      this.showCurrentState = "共有" + recordCount + "条记录数,每页" + pageSize + "条,第<font color=\"red\">"+ pageNum + "</font>页,"+"共" +pageCount + "页." ;
    }
    else
    {
      this.showCurrentState="";
    }
  }
  public String getShowCurrentState()
  {
    return showCurrentState;
  }
  //显示分页码
  public void setShowPageNumber(String path,String parameters,String first,String previous,String next,String last)
  {
    if(pageNum>1)
    {
     showPageNumber="<a href=\"" +path+ "?pageNum=1" +parameters+ "\">" +first+ "</a>&nbsp;";
     showPageNumber=showPageNumber+"<a href=\"" +path+ "?pageNum=" +(pageNum-1)+parameters+ "\">" +previous+ "</a>&nbsp;";
   }
   if(pageNum<pageCount)
   {
     showPageNumber=showPageNumber+"<a href=\"" +path+ "?pageNum=" +(pageNum+1)+parameters+ "\">" +next+ "</a>&nbsp;";
     showPageNumber=showPageNumber+"<a href=\"" +path+ "?pageNum=" +pageCount+parameters+ "\">" +last+ "</a>&nbsp;";
   }
  }
  public void setShowPageNumber(String path,String parameters,int middleSize,int kipSize)
  {
    int start=(pageNum/kipSize)*kipSize+1;
    int end=start-1+middleSize;
    if(end>=pageCount)
    {
      end=pageCount;
    }
    if(start>kipSize)
    {
      showPageNumber="<a href=" +path+ "?pageNum=" +(start-2)+parameters+ ">" +"<<<"+ "</a>&nbsp;";
    }
    while(start<=end)
    {
      showPageNumber=showPageNumber+"<a href=" +path+ "?pageNum=" +start+parameters+ ">[" +start+ "]</a>&nbsp;";
      start++;
    }
    if(end<pageCount)
    {
      showPageNumber=showPageNumber+"<a href=" +path+ "?pageNum=" +(end+1)+parameters+ ">" +">>>"+ "</a>&nbsp;";
    }
  }
  public String getShowPageNumber()
  {
    return showPageNumber;
  }
}

3.在JSP页面显示
 ${pagination.showPageNumber}  ,${pagination.showCurrentState}
posted on 2009-06-20 00:27 weesun一米阳光 阅读(4593) 评论(1)  编辑  收藏 所属分类: 总结备用SSH框架

评论

# re: struts2中如何获得request.setAttribute("bean", beanObject);的值得在JSP页面显示【自己整理】[未登录] 2011-12-22 19:15 菜鸟
谢谢!  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: