读书人

displaytag按需分页的包装及范例

发布时间: 2013-01-20 10:22:41 作者: rapoo

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 theorg.displaytag.pagination.PaginatedList interface. 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接口,此类在项目中公用,对于所有的分页需求界面,不需要另造轮子。

<display:table id="pagedatas" name="pagedatas" export="false" sort="external" class="dispaytag"  requestURI="queryIncidental"  decorator="com.whyonly.center.pos.mv.PosbatchWrapper"><display:column property="batchnum" paramId="batchnum" paramProperty="batchnum"  href="incidental" titleKey="centerowl.posinvoicing.searchtran2" /><display:column property="custname" titleKey="centerowl.posinvoicing.searchtran3" /><display:column property="ctime"titleKey="centerowl.posinvoicing.searchtran4" /><display:column property="createPerson.name" titleKey="centerowl.posinvoicing.searchtran5" /></display:table>

此处用了一个包装器,用于显示日期。如果不需要对数据进行特殊的处理,直接忽略他。







读书人网 >软件架构设计

热点推荐