lambdaWrapper进行多条件查询时,如何使用

lambdaWrapper进行多条件查询时,如何使用

我们知道数据库语句比较常用条件查询,但是多条件怎么办?
形如

select *
from table1
where
a = '''
and
b = ''
and c='''
and
(d = 1 or d = 2 or = d = 3

使用lambdaWrapper时候,要充分使用.and()和.or()

使用的代码如下

@Override
    public List<MallShopApptOrderEntity> listByCustomer(String customerId, LocalDateTime firstDay, LocalDateTime lastDay) {
        LambdaQueryWrapper<MallShopApptOrderEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MallShopApptOrderEntity::getCustomerId, customerId)
                .ge(MallShopApptOrderEntity::getPayTime, firstDay)
                .le(MallShopApptOrderEntity::getPayTime, lastDay)
                .and(m -> m.eq(MallShopApptOrderEntity::getOrderStatus, 1).
                        or().eq(MallShopApptOrderEntity::getOrderStatus, 2).
                        or().eq(MallShopApptOrderEntity::getOrderStatus, 3).
                        or().eq(MallShopApptOrderEntity::getOrderStatus, 4))
                .and(ms -> ms.eq(MallShopApptOrderEntity::getPayMethod, 2).
                        or().eq(MallShopApptOrderEntity::getPayMethod, 3).
                        or().eq(MallShopApptOrderEntity::getPayMethod, 5).
                        or().eq(MallShopApptOrderEntity::getPayMethod, 6).
                        or().eq(MallShopApptOrderEntity::getPayMethod, 7));
    return this.list(wrapper);
    }

编译出来的sql语句如下

 SELECT 
	*
 FROM mall_shop_appt_order 
 WHERE 
 (
 customer_id = '1559017565590265856' AND pay_time >= "2022-09-01" AND pay_time <= "2022-09-30" 
 AND ((order_status = 1 OR order_status = 2 OR order_status = 3 OR order_status = 4)) 
 AND ((pay_type = 2 OR pay_type = 3 OR pay_type = 5 OR pay_type = 6 OR pay_type = 7))
 )
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值