Normally you want your database to do the heavy lifting for pagination and sorting. With MySQL for example you can get a page of results sorted by date by adding
ORDER BY date ASC LIMIT 5,5
页: 1 如果你使用保密标准,你可以依靠供应商独立的方式这样做:
List<MyDomainClass> results = (List<MyDomainClass>) getSession()
.createCriteria(MyDomainClass.class)
.setFirstResult(5)
.setMaxResults(5)
.addOrder(Order.asc("date"))
.list();
To display a pagination navigation you also need to count the total number of results to know how many pages there are:
int count = (int) getSession()
.createCriteria(MyDomainClass.class)
.setProjection(Projections.rowCount())
.list().get(0);
You can add restrictions to both searches, for example when you want to filter on lastname you could add:
.add(Restrictions.eq("lastname", "Smith")
(需要在计票单和清单查询中加上这一点)。
如果你知道结果总数、页数和目前的页数,你就可以计算结果范围,如:
// TODO: execute the count query here to determine totalResults
int totalPages = Math.ceil(totalResults / pageSize);
// show first page by default
int firstResult = 0;
if (currentPage >= 0 && currentPage < totalPages) {
firstResult = currentPage * pageSize;
}
// the number of items might be less than the page size (i.e. on the last page)
int count = Math.min(pageSize, totalResults - firstResult);
// TODO: execute the list query here to get a page of data
你们是如何展示航海的。 有些框架有这方面的标准组成部分。 否则,你就必须想办法处理大量页数。 一种共同做法是展示出10页数,并显示开始/恢复的跳跃,以结束链接。
Hope this helps.