hibernate分页查询的各种方法

统计总数:

	public Integer countAll1() {

			String hql = "select count(*) from News as news";
List list = getHibernateTemplate().find(hql);
return list.get(0).hashCode();
} public Integer countAll2() { Criteria criteria = this.getSession().createCriteria(News.class);
return ((Integer) (criteria.setProjection(Projections.rowCount())).uniqueResult()).intValue();
}

分页查询:

	public List pagerList(Integer beginNum,Integer maxNum){
DetachedCriteria dCriteria = DetachedCriteria.forClass(News.class);
List list = getHibernateTemplate().findByCriteria(dCriteria, beginNum, maxNum);
return list;
} public List pagerList1(String news,Integer beginNum,Integer maxNum){
Criteria criteria = this.getSession().createCriteria(News.class);
criteria.setFirstResult(beginNum);
criteria.setMaxResults(maxNum);
return criteria.list();
} public List pagerList2(String news,Integer beginNum,Integer maxNum){
String hql = "from News";
Query query = this.getSession().createQuery(hql);
query.setFirstResult(beginNum);
query.setMaxResults(maxNum);
return query.list();
}

  

 

上一篇:OpenJudge 2773 2726 2727 采药


下一篇:Sublime Text 快捷键列表