模糊查询中,会有针对一个数据,需要查询数据库的多个字段的情况,例如:
上图中的平台名称和平台进程在数据表中是两个不同的字段,
如果不使用Mybatisplus,仅使用Mybatis,则只有通过写xml的方式进行手动书写SQL,这样效率不高,针对这种SQL中可能出现or(),and()之类的条件,Mybatisplus提供了很好的解决方案:
@Override public IPage<SpeedDownloadInfo> listSpeedDownInfo(SpeedDownloadRequest request, Integer pageNo, Integer pageSize) { LambdaQueryWrapper<SpeedDownloadInfo> queryWrapper = Wrappers.<SpeedDownloadInfo>lambdaQuery() .between(SpeedDownloadInfo::getCreateTime, DateUtil.beginOfDay(request.getBegin()), DateUtil.endOfDay(request.getEnd())) .and(!StringUtils.isEmpty(request.getQueryString()), wrapper -> wrapper.like(SpeedDownloadInfo::getPlatformName, request.getQueryString()) .or().like(SpeedDownloadInfo::getPlatformDomain, request.getQueryString())); return speedDownloadInfoMapper.selectPage(new Page<>(pageNo,pageSize),queryWrapper); }
以上代码等价为
SELECT * FROM speed_download_info WHERE create_time BETWEEN ? AND ? AND ( platform_name LIKE ? OR platform_domain LIKE ? )
参考:
https://blog.csdn.net/mojiewangday/article/details/108223785?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.add_param_isCf&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.add_param_isCf