Spring data QuerydslBindings exampls

bindings.bind(store.address.city).single((path, value)->path.endsWith(value));

bindings.bind(String.class).single((StringPathpath,Stringvalue)->path.contains(value));

--不綁定password字段,即password字段不作為查詢條件

bindings.excluding(root.password);

http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.type-safe

--頁面?zhèn)鬟fdateOfBirth數(shù)組,包括mininum,maxinum。注意:對(duì)于mongo,between $min and $max,因此頁面?zhèn)鬟f參數(shù)時(shí),第一個(gè)element為小值,第二個(gè)為大值。

bindings.bind(user.dateOfBirth).all((path,value)->{

? ? ? Iterator?it=value.iterator();

? ? ? return path.between(it.next(),it.next());//--需要進(jìn)行Object cast到path指定類型

}

);

org.springframework.data.querydsl.binding.QuerydslBindings判斷一個(gè)屬性是否pathVisible規(guī)則:

this.aliases.contains(path) &&?

!this.blackList.contains(path)?true:(this.whiteList.isEmpty()?(this.excludeUnlistedProperties?false:!this.blackList.contains(path)):this.whiteList.contains(path));

針對(duì)關(guān)系型數(shù)據(jù)庫,使用ElementCollection表示Map類型字段。

@Entity

public class Product extends AbstractEntity {

@ElementCollection

private Map<String, String> attributes = new HashMap(); }

Order的構(gòu)造函數(shù)使用了對(duì)象copy,這樣做避免Customer在修改了Address后,Order中的地址不會(huì)變化。

public Order(Customer customer, Address shippingAddress, Address billingAddress) {

Assert.notNull(customer);

Assert.notNull(shippingAddress);

this.customer = customer;

this.shippingAddress = shippingAddress.getCopy();

this.billingAddress = billingAddress == null ? null : billingAddress.getCopy();

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容