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

--页面传递dateOfBirth数组,包括mininum,maxinum。注意:对于mongo,between $min and $max,因此页面传递参数时,第一个element为小值,第二个为大值。

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

      Iterator it=value.iterator();

      return path.between(it.next(),it.next());//--需要进行Object cast到path指定类型

}

);

org.springframework.data.querydsl.binding.QuerydslBindings判断一个属性是否pathVisible规则:

this.aliases.contains(path) && 

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

针对关系型数据库,使用ElementCollection表示Map类型字段。

@Entity

public class Product extends AbstractEntity {

@ElementCollection

private Map attributes = new HashMap(); }

Order的构造函数使用了对象copy,这样做避免Customer在修改了Address后,Order中的地址不会变化。

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();

}

你可能感兴趣的:(Spring data QuerydslBindings exampls)