SpringbootDataJpa條件查詢和分頁

2021-10-01 05:41:23 字數 1262 閱讀 1668

public queryresponseresult findallpage(int page, int size, requestdata requestdata)

//自定義條件查詢

//定義條件匹配器

examplematcher examplematcher = examplematcher.matching()

.withmatcher("chinese", examplematcher.genericpropertymatchers.contains())

.withmatcher("english",examplematcher.genericpropertymatchers.contains());

term term = new term();

//設定查詢條件

if(stringutils.isnotempty(requestdata.getchinese()))

if(stringutils.isnotempty(requestdata.getenglish()))

//定義條件物件example

exampleexample = example.of(term,examplematcher);

if(page<=0)

page=page-1;

if(size<=0)

pageable pageable = pagerequest.of(page,size);

pageall = termrepository.findall(example,pageable);//實現自定義條件查詢並且分頁查詢

queryresult queryresult = new queryresult();

queryresult.setlist(all.getcontent());//資料列表

queryresult.settotal(all.gettotalelements());//資料總記錄數

queryresponseresult queryresponseresult = new queryresponseresult(commoncode.success,queryresult);

return queryresponseresult;

}

examplematcher是乙個查詢條件匹配器,用來設定查詢的條件是模糊查詢或精確查詢等等。

example用來存放查詢物件和查詢方式。

pageable用來存放頁碼和每頁顯示多少條記錄,

findall()把兩個東西放進來。

php 條件查詢和多條件查詢

條件迴圈 public w3c dtd xhtml 1.0 transitional en 代號名稱 系列時間 油耗功率 include dbda.class.php db new dbda tj name if empty post sql select from car tj attr db q...

mysql分條件查詢 choose

一 問題描述 在完成某個介面時,發現需求是這樣的 如果是管理員角色,要查詢所有資訊 如果是非管理員使用者,則按照當前登入使用者的類別來進行查詢,最簡單是拆分成兩個sql語句,但是這種寫法有點low,還是寫成乙個分條件查詢sql語句。二 實現 1 業務層關鍵 實現 hashmapmap new has...

mysql分頁和條件查詢 資料庫 條件查詢和分頁

productdao dao newproductdao 目的 就是想辦法封裝乙個pagebean 並返回 pagebean pagebean newpagebean 1 當前頁private int currentpage pagebean.setcurrentpage currentpage 2...