欢迎来到天天文库
浏览记录
ID:11283016
大小:26.50 KB
页数:5页
时间:2018-07-11
《重构struts2 jsp分页》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、前两天的Struts2JSP分页由于过于关注框架实现,导致结构比较混乱。经过一些改动,再次发布。环境是JDK1.6+mysql5.0+jboss4.0+struts2.0.11已经实现上一版没实现的功能。首先来看UML图,为了简洁性,其中的setter&getter并没有标出。publicclassShowActionextendsActionSupport{privateintcurrentPage=1;privateinttotalPages;privatebooleanhasNext=false;privatebooleanhasPre=false;pr
2、ivateArrayListpageContentList;privateArrayListindexListprivatePageRetrievalpr;publicStringexecute(){init();returnSUCCESS;}privatevoidinit(){pr=newPageRetrieval(currentPage);setPageContentList(pr.getPageContentList());setndexList(pr.getIndexList());setHasNext(pr.getHasNext
3、());setHasPre(pr.getHasPre());setTotalPages(pr.getTotalPages());}//othergettersandsetters}publicclassPageRetrieval{privatePageInformationpi;publicPageRetrieval(intcurrentPage){pi=newPageInformationFactory().create(currentPage);}publicintgetTotalPages(){returnpi.getPti().getTotalPage
4、s();//othergettersandsetters}publicclassPageInformationFactory{privateDatabaseServicesdataServ;publicPageInformationFactory(){dataServ=MyDatabaseServices.getInstance();}publicPageInformationcreate(intcurrentPage){PageInformationpi=newPageInformation();PageTotalInfopti=getNewPageTota
5、lInfo();pi.setPti(pti);if(currentPageindexTemp=getIndexList(currentPage,pti.getTo
6、talPages());pi.setIndexList(indexTemp);returnpi;本文来自哈客部落Hake.cc}privatePageTotalInfogetNewPageTotalInfo(){intpageSize=20;inttotalRows=((MyDatabaseServices)dataServ).getRowCount();inttotalPages=(totalRows+pageSize-1)/pageSize;returnnewPageTotalInfo(pageSize,totalPages,totalRows);}pri
7、vateArrayListgetIndexList(intcurrentPage,inttotalPages){intup=0;if((currentPage+20)<=totalPages){up=currentPage+20;}else{up=totalPages+1;}ArayListresult=newArrayList();for(inti=currentPage;i8、urnresult;}}publicc
8、urnresult;}}publicc
此文档下载收益归作者所有