1. 程式人生 > >hibernate分頁查詢

hibernate分頁查詢

package cn.itcast.b;

import javax.swing.Scrollable;

import org.hibernate.Query;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

public class App_page {
	private static SessionFactory sf;
	static {
		sf=new Configuration().configure().buildSessionFactory();
	}
	@Test
	public void Page(){
		Session session=sf.openSession();
		session.beginTransaction();
		
		Query q=session.createQuery("from Cat");
		ScrollableResults scroll=q.scroll();//得到滾動的結果集
		scroll.last();//滾動到最後一行
		int totalCount=scroll.getRowNumber()+1;//得到滾動的記錄數,即總資料數
		
		//設定分頁引數
		q.setFirstResult(0);
		q.setMaxResults(3);
		
		System.out.println(q.list());
		System.out.println("總記錄數"+totalCount);
		
		session.getTransaction();
		session.close();
	}
}

相關推薦

hibernate查詢

package cn.itcast.b; import javax.swing.Scrollable; import org.hibernate.Query; import org.hibernate.ScrollableResults; import org.hibe

淺談ORDER排序對HIBERNATE查詢的影響

    hql = hql + " ORDER BY isSystem";         hql4Tot =hql4Tot+" ORDER BY isSystem";                  Query query = this.getHibernateTemp

hibernate查詢

urn reat string lis per creat spa max 數據 hibernate的分頁查詢有個好處,就是不用管數據庫方言。比如db2的分頁查詢很麻煩,但是用hibernate的方式,就完全不用管這些了 /* 使用HQL分頁查詢Customer信息

Hibernate 利用Criteria一次性查詢資料和總數

拿到SessionFactory建立Criteria物件 Criteria c = session.createCriteria(Case.class); //插入查詢條件 ... //計算總數 c.set

daoImpl裡呼叫getSession(),hibernate DetachedCriteria Criteria進行查詢

DaoImpl裡呼叫getSession() public class SocialInfoDaoImpl extends BaseDaoImpl<SocialInfo,Integer> implements ISocialInfoDao { pub

Hibernate.Criteria完成多件條組合查詢

//需要先行搭建好框架,建立好一個實體類Student及一個Util類pageBean public class StudentDaoImpl implements IStudentDao { @Overridepublic PageBean find(int pageIn

hibernate兩表關聯查詢

核心實現程式碼: @Override public Map<String ,Object> getBackUserNurseBeanList( String name, Integer pageNo) { if(pageNo == n

Hibernate中的查詢

一、hibernate分頁查詢: 方法: setFirstResult:設定查詢開始的記錄 setMaxResults:設定每次查詢的條數 /** * 查詢全部文章的過載 * 分頁查詢 * @param currentPage 當前頁面 * @param maxR

使用Hibernate criteria進行查詢時,如何實現一次查詢取得總記錄數和後結果集

可先使用 Projections.rowCount() 來取得總記錄數,如下: Long totalNum = (Long)criteria.setProjection(Projections.rowCount()).uniqueResult(); 然後將 Project

Hibernate如何使用HQL語句實現資料查詢

實現資料分頁查詢 使用Query介面的 setFirstResult (int firstResult) 方法 和 setMaxResult (int maxResult) 方法實現 setFirstResult (int firstResult) 方法 :設定返回

Hibernate查詢方法總結(包括條件查詢、外來鍵id查詢

每天進步一點點,最近做專案用到了很多的hibernate的查詢方法。正好騰出時間來總結,希望對自己和他人都有幫助。 首先非常感謝施楊 's think out 和suntao1983做的總結,幫我解決的很多問題。 hibernate 的 六種基本查詢方法:分別是HQL查詢

Hibernate中使用HQL進行查詢

第一步 建立query物件 Query query = session.createQuery("xxxxxx”); 第二步 設定開始位置和每頁顯示記錄數 設定開始位置,firstResult 的內

Hibernate查詢,返回new物件(注意這個新定義的類要有建構函式),使用sql帶條件查詢並且把結果顯示到一個物件的集裡面的解決方案

IIndexDaopackage com.ucap.netcheck.dao;import com.ucap.netcheck.combination.beans.IndexCombinationBean;import com.ucap.netcheck.common.P

Hibernate多條件模糊查詢

因為要做一個分頁的功能,所以就上網隨便找了一個hibernate分頁的例項,但是總是報出: org.hibernate.QueryParameterException: could not locate named parameter這個惱人的錯誤,卻又查不到

關於SpringMVC+Hibernate框架的關聯查詢查詢

一、hibernete的關聯查詢 hibernete使用多表查詢,並且要求查詢某表中的某些指定欄位時,就需要自己在實體類中建立一個用於關聯查詢的物件。因為getCurrentSession().createQuery()方法返回的是Object物件陣列,無法強

HBase多條件及查詢的一些方法

nosql數據庫 應用場景 實現簡單 信息 byte 多條 多個 不可用 寫性能 HBase是Apache Hadoop生態系統中的重要一員,它的海量數據存儲能力,超高的數據讀寫性能,以及優秀的可擴展性使之成為最受歡迎的NoSQL數據庫之一。它超強的插入和讀取性能與它的數據

查詢

參數 phone nbsp 數量 返回 res cnblogs 獲取參數 註意 <!-- 分頁 --> <sql id="paging"> <if test="isPage != null and isPage

2017-5-24 查詢,組合查詢

操作類 form first trim parameter emp use hashtable ack 分頁查詢 組合查詢 1.用到的實體類: public class ab { public int Ids { get; set; } publ

bos 第4 (區域excel批量導入、區域通用查詢區的添加、區多條件查詢區導出excel)

sea htm 不能 長安 基金會 格式 address ret body BOS項目筆記 第4天 今天內容安排: 1、區域批量導入功能 jQuery OCUpload(一鍵上傳插件)、apache POI、pinyin4j 2、實現區域的分頁查詢 3、對分頁代碼重構

Linq高級查詢查詢

lec end context orderby ice source contains sco 平均值 Linq高級查詢 以~開頭: r=>r.Name.StartsWith("李"); 以~結尾: r=>r.Name.EndsWith("光"); 包含(模糊查