baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.4k stars 4.31k forks source link

[功能改进]: 条件构造器支持传入另一个 QueryWrapper 作为条件值 #6353

Open rui8832 opened 3 months ago

rui8832 commented 3 months ago

当前程序版本

v3.5.7

功能改进

当前查询条件:

    // 查询条件:联系人
    if (StringUtils.isNotEmpty(req.getContactName())
        && !SqlInjectionUtils.check(req.getContactName())) {
      // 阿弥陀佛,罪过罪过
      String sql_contact =
          String.format(
              "SELECT clue_id FROM cl_clue_contact WHERE `name` LIKE '%%%s%%'",
              req.getContactName());
      lqwr.inSql(ClClueInfoEntity::getId, sql_contact);
    }

期望查询条件:

    // 查询条件:联系人
    if (StringUtils.isNotEmpty(req.getContactName())) {
      LambdaQueryWrapper<ClClueContactEntity> lqwr_contact = new LambdaQueryWrapper<>();
      lqwr_contact.select(ClClueContactEntity::getClueId);
      lqwr_contact.like(ClClueContactEntity::getName, "%" + req.getContactName() + "%");
      lqwr.inSql(ClClueInfoEntity::getId, lqwr_contact);
    }

参考资料

No response