Hibernate分页查询
1.实现分页查询数据
public List<Emp> empList(int pageIndex,int pageSize){
return HibernateSessionFactory.getSession().createQuery("from Emp")
.setFirstResult((pageIndex-1)*pageSize)//起始下标
.setMaxResults(pageSize)//每页显示条数
.list();
}
2.得出总条数
public long countEmp(){ //HibernateSessionFactory.getSession().createQuery("select count(empNo) from Emp").get(0); return (long) HibernateSessionFactory.getSession().createQuery("select count(empNo) from Emp").uniqueResult(); }
3.求总页数
int pageCount=count%3==0?count/3:count/3+1;

浙公网安备 33010602011771号