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;

 

 

posted @ 2018-03-19 12:31  Quest1on  阅读(110)  评论(0编辑  收藏  举报