SpringBoot中Example的動態條件查詢

2022-07-22 03:24:15 字數 1420 閱讀 9814

一、無匹配器的情況:
person person = new

person();

person.setname("test");

role role = new

role();

role.setname("經理");

person.setrole(role);

...

example

ex = example.of(person); //

動態查詢

personrepository.findall(ex);

personrepository.findall(ex,pageable);

//分頁

二、匹配器多條件組合(自己多動手試試各種各樣的條件組合)
person person = new

person();

person.setname(name);

//預設匹配器:字串採用精準查詢,忽略大小寫(文件說不忽略大小寫,本人測試時發現是忽略大小寫的)

examplematcher matcher =examplematcher.matching()

//.withstringmatcher(examplematcher.stringmatcher.containing)

//改變預設字串匹配為:模糊查詢

//.withmatcher("name", examplematcher.genericpropertymatchers.contains())

//name欄位模糊匹配

//.withmatcher("name", examplematcher.genericpropertymatchers.startswith())

//name欄位開頭模糊匹配

//.withmatcher("name", examplematcher.genericpropertymatchers.endswith())

//name欄位結尾模糊匹配

//.withignorepaths("id","phone");

//忽略id,phone欄位

exampleex = example.of(person,matcher); //

動態查詢

return

personrepository.findall(ex);

retuen personrepository.fiadall(ex,pageable)

//分頁

總結:

(person) 一對一,多對一可以通過set另外乙個實體(role)的字段來實現動態查詢,但是(person)一對多通過example來動態查詢,本人試過不行(jpaspecificationexecutor可以),你們又沒有idea?

集訓試題 exam 信心考 最小割

題意概述 有n個人,a,b兩個考場。如果學生i在a考場,總信心值增加xi 如果學生i在b考場,總信心值增加yi。其中還有m對好友,當第i對好友的兩個人都在a考場時,總信心值增加ai 如果兩人都在b考場,總信心值增加bi 如果兩個人在不同考場,那麼總信心值減少ci。問總信心值最大能達到多少 總信心值的...

HDU 4473 Exam 數學分析

題意 給定乙個數x,現在定義f x 是a b x的情況下,a,b的組合情況有多少種。現在給定乙個數n求f 1 f 2 f n 解法 一開始想到了a b是x的約數,因此推出了f x 的公式 也就是這個公式,使得我們在求字首和的道路上寸步難行.正確的解法是對於任意乙個a b c可以視為a b c x,那...

Springboot中Thymeleaf外部模板

spingboot專案中,預設的thymeleaf模板資料夾是在 src main resources templates,打包時後在classpath templates下 jar包同目錄下的 templates 目錄 spring.thymeleaf.prefix file templates ...