99re热视频这里只精品,久久久天堂国产精品女人,国产av一区二区三区,久久久精品成人免费看片,99久久精品免费看国产一区二区三区

查詢數據-ESQL方式

2018-05-31 09:45 更新

框架中提供了一個專門用于執(zhí)行esql和sql的api類。esql就是sql語句,但是只從where條件關鍵字開始編寫的后面部分,該api類是

org.myhibernate.core.method.Query , 獲取方式如下

Template<Product> template=new ProxyTemplate(Product.class).getInstance();
		Query<Product> query=template.getQuery();
		try 
		{
			// ???
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally
		{
			template.close();
		}


第一組查詢api方法如下

public int query(String esql)  該方法返回esql查詢后返回的結果數 ,查詢的是所有數據的id值,是框架內存分頁

public List<T> getResults(int start,int end)  該方法用以對上面查詢的結果進行分頁獲取


public  List<T> queryAll()  獲取所有結果

public  List<T> queryAll(String esql,boolean isCache) 獲取所有結果,并可以傳入esql條件過濾,和指定是否緩存

如下獲取滿足條件的第10到20條記錄示例

Template<Product> template=new ProxyTemplate(Product.class).getInstance();
		Query<Product> query=template.getQuery();
		try 
		{
			int count=query.query("where price>50");
			List<Product> products=query.getResults(10, 20);
		} catch (Exception e) {
			e.printStackTrace();
		}finally
		{
			template.close();
		}


如下獲取滿足條件的所有記錄 示例

Template<Product> template=new ProxyTemplate(Product.class).getInstance();
		Query<Product> query=template.getQuery();
		try 
		{
			List<Product> products= query.queryAll("where price>50", true);
		} catch (Exception e) {
			e.printStackTrace();
		}finally
		{
			template.close();
		}


第二組查詢api方法如下

public List<T> where(String esql,int start,int size)  查詢滿足esql條件的記錄,并且分頁,采用的是數據庫分頁

public List<T> where(String esql,Object[] values,int start,int size) 查詢滿足esql 預編譯方式條件的記錄,并且分頁

這兩個方法和getCount() 獲取記錄條數一起使用

示例如下

Template<Product> template=new ProxyTemplate(Product.class).getInstance();
		Query<Product> query=template.getQuery();
		try 
		{
			List<Product> products=query.where("where price>50", 0, 10);
			int count=query.getCount();
		} catch (Exception e) {
			e.printStackTrace();
		}finally
		{
			template.close();
		}


第三組查詢api

   Query中提供了幾個封裝的查詢方法,以find開頭的,讀者自己測試測試即可







以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號