2010年5月20日 星期四
Hibernate Pagination
http://blog.hibernate.org/Bloggers/Everyone/Year/2004/Month/08/Day/14#pagination
public class Page {
private List results;
private int pageSize;
private int page;
public Page(Query query, int page, int pageSize) {
this.page = page;
this.pageSize = pageSize;
results = query.setFirstResult(page * pageSize).setMaxResults(pageSize + 1).list();
}
public boolean isNextPage() {
return results.size() > pageSize;
}
public boolean isPreviousPage() {
return page > 0;
}
public List getList() {
return isNextPage() ? results.subList(0, pageSize - 1) : results;
}
}
訂閱:
文章 (Atom)