当前位置 : 主页 > 编程语言 > java >

mybatis plus or and 的合并写法实例

来源:互联网 收集:自由互联 发布时间:2021-04-03
我就废话不多说了,大家还是直接看代码吧~ int count =hrDeliverEmployContractService.selectCount(new EntityWrapperHrDeliverEmployContractEntity().eq("pool_id",hrDeliverEmployContract.getPoolId()).andNew().lt("contract_start_

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

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

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使用

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

对应sql语句

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语句

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

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

网友评论