Query query = session.createQuery(“from User”);
List users = query.list();
System.out.println(users.size());
Number pageCount = users.size() / 5;
int p = users.size() % 5;
int pageSize = (int) pageCount;
if (p!= 0) {
pageSize++;
}
for (int i = 0; i < pageSize; i++) {
System.out.println(“第” + (i + 1) + “页”);
query.setFirstResult(i * 5);
query.setMaxResults(5);
List users1 = query.list();
for (int j = 0; j < users1.size(); j++) {
User user = (User) users1.get(j);
System.out.println(user.toString());
}
}
09-05
09-05
09-05