最近我在一個blaog上看到一個老兄關(guān)于displaytag解決大數(shù)據(jù)量的文章。他是用封裝displaytag的方式寫了一個displaytagpro。我個人覺得沒有必要。一是封裝后的即使解決了大數(shù)據(jù)量的問題,將來升級也是個問題,難道還有天天關(guān)注你的程序更新?二是其實displaytag已經(jīng)解決了大數(shù)據(jù)量分頁的問題。解決的補丁可以從這里下載
DISPL-134.zip 。該補丁增加了table的virtualSize屬性。
解決方式大致如下:
jsp:
<display:table class="list" name="<%= CodeListAction.CODE_LIST_KEY %>" id="row" pageSize="20" virtualSize="<%= ((Integer)request.getAttribute (CodeListAction.CODE_LIST_SIZE_KEY)).toString() %>" requestURI="codelist.do" sort="list">
在數(shù)據(jù)量大時
可以設(shè)置virtualSize屬性,表示總記錄數(shù)。
action:// Get the page number requested
int page = 1;
int size = 20;
Enumeration paramNames = request.getParameterNames
();
while (paramNames.hasMoreElements()) {
String name = (String)paramNames.nextElement();
if (name != null && name.startsWith("d-") &&
name.endsWith("-p")) {
String pageValue = request.getParameter(name);
if (pageValue != null) {
page = Integer.parseInt(pageValue);
}
}
}
DB:
數(shù)據(jù)層你可以根據(jù)數(shù)據(jù)庫的不同寫不同的adapter。下面是針對oracle的特性寫的。
select * from (
select query.*, rownum rnum from (
your complete query goes here....
) query where rownum <= (:pagingNo*:pagingSize)
) where rnum >= ((:pagingNo-1)*:pagingSize)+1 order by rnum
這樣就可以了。該問題可以查看
http://jira.codehaus.org/browse/DISPL-134要想更好的控制分頁,就用valuelist ,Extreme Table了。
風(fēng)之語