我有一个查询来按客户,电子邮件和电话的名称过滤订单
@Query(value = "{ $and: [ { 'fullName' : {$regex:?0,$options:'i'} },
{ 'phone' : {$regex:?1,$options:'i'}},
{ 'email' : {$regex:?2,$options:'i'}} ] }")
Page<Order> filter(String fullName, String phone, String email, Pageable pageable);
它可以工作,但只选择所有搜索字段都不为空的订单。如何更改查询以获取更多订单?
在SQL中,它将类似于:
where (order.fullName Like queryfullName or queryfullName is null or order.fullName is null)
and (order.phone Like queryphone or queryphone is null or order.phone is null)
and (order.email Like queryemail or queryemail is null or order.email is null)