• 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();
    	}
    

      

     

  • 相关阅读:
    POJ 1511
    POJ 1125
    POJ 2240
    POJ 1459
    POJ 1274
    POJ 1789
    POJ 2485,1258
    POJ 1236
    POJ 1273
    Ruby on Rails 观后感
  • 原文地址:https://www.cnblogs.com/koal/p/4451775.html
Copyright © 2020-2023  润新知