mybatis-plus批量操作自定义条件
直接上干货
return SqlHelper.saveOrUpdateBatch(Entity.class, Mapper.class, super.log, list, DEFAULT_BATCH_SIZE, (sqlSession, entity) -> {
LambdaQueryWrapper<Entity> queryWrapper = Wrappers.<Entity>lambdaQuery().eq(Entity::getId, entity.getId());
Map<String, Object> map = com.baomidou.mybatisplus.core.toolkit.CollectionUtils.newHashMapWithExpectedSize(1);
map.put(com.baomidou.mybatisplus.core.toolkit.Constants.WRAPPER, queryWrapper);
return CollectionUtils.isEmpty(sqlSession.selectList(getSqlStatement(SqlMethod.SELECT_LIST), map));
}, (sqlSession, entity) -> {
LambdaUpdateWrapper<Entity> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(Entity::getId, entity.getId());
Map<String, Object> param = com.baomidou.mybatisplus.core.toolkit.CollectionUtils.newHashMapWithExpectedSize(2);
param.put(com.baomidou.mybatisplus.core.toolkit.Constants.ENTITY, entity);
param.put(com.baomidou.mybatisplus.core.toolkit.Constants.WRAPPER, lambdaUpdateWrapper);
sqlSession.update(getSqlStatement(SqlMethod.UPDATE), param);
});