displaytag按需分页的包装及实例
displaytag1.1之后支持按需进行分页查询,在其官方网站有如下描述:Displaytag 1.1 offers two alternative ways for working with partial lists:the first one uses the valuelist pattern, and requires that the object that you give to displaytag implements the org.displaytag.pagination.PaginatedList inte易做图ce. You can pass this object to displaytag as an usual list, and it will extract paging and sorting information from it. This way is more recommended if you have to build your backend layer and you can easily follow this pattern.a second way, recommended if you only have to use partial list for few tables that show a performance problem using full lists, is passing all the needed parameters as separate tag attributes (recors to be shown, page number, total number of records...)参考:http://www.displaytag.org/1.2/tut_externalSortAndPage.html当存在大数据量的时候,一般使用第一种方法。本文的示例来自实际项目,主要解决两个问题:1) 按需取得数据,利用displaytag实现页面分页显示。2) 对displaytag要求的分页参数进行设置及复杂性包装,便于快速开发。主要的步骤如下:1、创建一个简单类实现org.displaytag.pagination.PaginatedList接口,此类在项目中公用,对于所有的分页需求界面,不需要另造轮子。[java]package com.whyonly.core.displaytag;import java.util.List;import org.displaytag.pagination.PaginatedList;import org.displaytag.properties.SortOrderEnum;public class SimplePaginatedList<T> implements PaginatedList {private List<T> list;private int pageNumber = 1;private int objectsPerPage = 20;private int fullListSize = 0;private String sortCriterion;private SortOrderEnum sortDirection;private String searchId;public List<T> getList() {return list;}public void setList(List<T> list) {this.list = list;}public int getPageNumber() {return pageNumber;}public void setPageNumber(int pageNumber) {this.pageNumber = pageNumber;}public int getObjectsPerPage() {return objectsPerPage;}public void setObjectsPerPage(int objectsPerPage) {this.objectsPerPage = objectsPerPage;}public int getFullListSize() {return fullListSize;}public void setFullListSize(int fullListSize) {this.fullListSize = fullListSize;}public String getSortCriterion() {return sortCriterion;}public void setSortCriterion(String sortCriterion) {this.sortCriterion = sortCriterion;}public SortOrderEnum getSortDirection() {return sortDirection;}public void setSortDirection(SortOrderEnum sortDirection) {this.sortDirection = sortDirection;}public String getSearchId() {return searchId;}public void setSearchId(String searchId) {this.searchId = searchId;}}2,创建一个分页包装器,根据displaytag分页的要求包装共同性,同时把不同的部分通过接口的方式让子类去处理,此包装器也在项目易做图用。[java]package com.whyonly.core.displaytag;import java.util.List;import javax.servlet.http.HttpServletRequest;public abstract class PaginatedWrapper<T> {private int pageSize = 20;public void paginated(HttpServletRequest request) {int page = 1;if (request.getParameter("pageSize") != null&& !"".equals(request.getParameter("pageSize"))) {pageSize = Integer.parseInt(request.getParameter("pageSize"));} else {pageSize = 20;}if (request.getParameter("page") != null&& !"".equals(request.getParameter("page"))) {page = Integer.parseInt(request.getParameter("page"));} else {page = 1;}int fromIndex = (page - 1) * pageSize;int toIndex = fromIndex + pageSize;int fullListSize = getFullListSize();List<T> pageDatas = getPageDatas(fromIndex, toIndex);SimplePaginatedList<T> paginatedList = new SimplePaginatedList<T>();paginatedList.setPageNumber(page);if (pageDatas != null && pageDatas.size() > 0 && fullListSize > 0) {paginatedList.setFullL补充:软件开发 , Java ,
上一个:java书中小例子
下一个:Java进程在Unix平台上中文乱码问题
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- jsp+javaBean中Column 'ordersPrice' specified twice的错误
- Java TCP/IP Socket网络编程系列
- 大家来讨论一下我到底该用什么好?Swing 还是 JavaFX
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- spring 获取上下文问题
- SSH 导入导出excel 谁有这块的资料吗?
- Ext TreePanel 刷新问题
- springmvc 加载一个jsp页面执行多个方法 报404
- checkbox数组action怎么向页面传值