2

我有一个查询要按客户名称、电子邮件和电话过滤订单

@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)
4

0 回答 0