分页查询
Query query = session.createQuery("from User");
List users = query.list();
System.out.println(users.size());
Number pageCount = users.size() / 10;
int i1 = users.size() % 10;
int pageSize = (int) pageCount;
if (i1 != 0) {
pageSize++;
}
for (int i = 0; i < pageSize; i++) {
System.out.println("#第" + (i + 1) + "页");
query.setFirstResult(i * 10);
query.setMaxResults(10);
List users1 = query.list();
for (int j = 0; j < users1.size(); j++) {
User user = (User) users1.get(j);
System.out.println(user.toString());
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e966143f32da482c14563b84f13d3974.png)