mybatis plus or and 的合并写法实例

时间:2022-11-04 10:02:13

我就废话不多说了,大家还是直接看代码吧~

?
1
2
int count =hrDeliverEmployContractService.selectCount(new EntityWrapper<HrDeliverEmployContractEntity>()
.eq("pool_id",hrDeliverEmployContract.getPoolId()).andNew().lt("contract_start_date",hrDeliverEmployContract.getContractStartDate()).or().gt("contract_end_date",hrDeliverEmployContract.getContractEndDate()) );

对应的SQL

?
1
2
3
SELECT COUNT(1)
FROM hr_deliver_employ_contract
WHERE (pool_id = 1) AND (contract_start_date < '2018-07-01 00:00:00.0' OR contract_end_date > '2018-10-31 00:00:00.0');

补充:mybatis plus or使用

?
1
2
3
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper .and(wrapper -> wrapper.isNull(“sim”).or().eq(“sim”, “”));
queryWrapper .eq(“is_delete”, “0”);

对应sql语句

?
1
2
3
select * from vehicle where (sim is null or sim='') and is_delete=‘0'
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper .eq(“name”,“测试”).or().eq(“sim”,“2”);

对应sql语句

?
1
select * from vehicle where name=‘测试' or sim=‘2'

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。

原文链接:https://blog.csdn.net/liuming690452074/article/details/82775614