List<TVehcertUploadLog> list = tVehcertUploadLogService.list(new LambdaQueryWrapper<TVehcertUploadLog>().eq(StringUtils.isNotBlank(tVehcertUploadLog.getVin()),TVehcertUploadLog::getVin,tVehcertUploadLog.getVin()) .eq(StringUtils.isNotBlank(tVehcertUploadLog.getVehWzhgzbh()),TVehcertUploadLog::getVehWzhgzbh,tVehcertUploadLog.getVehWzhgzbh()) .like(StringUtils.isNotBlank(tVehcertUploadLog.getBz()),TVehcertUploadLog::getBz,tVehcertUploadLog.getBz()) .eq(StringUtils.isNotBlank(tVehcertUploadLog.getIsValid()),TVehcertUploadLog::getIsValid,tVehcertUploadLog.getIsValid()) .eq(StringUtils.isNotBlank(tVehcertUploadLog.getIsSample()),TVehcertUploadLog::getIsSample,tVehcertUploadLog.getIsSample()) .eq(StringUtils.isNotBlank(tVehcertUploadLog.getCreateBy()),TVehcertUploadLog::getCreateBy,tVehcertUploadLog.getCreateBy()) .ge(tVehcertUploadLog.getParams().containsKey("startTime")&&StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("startTime").toString()), TVehcertUploadLog::getUpDate,tVehcertUploadLog.getParams().containsKey("startTime")&&StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("startTime").toString())?sdf.parse(tVehcertUploadLog.getParams().get("startTime").toString()):"") .le(tVehcertUploadLog.getParams().containsKey("endTime")&&StringUtils.isNotEmpty(tVehcertUploadLog .getParams().get("endTime").toString()),TVehcertUploadLog::getUpDate,tVehcertUploadLog.getParams().containsKey("endTime")&&StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("endTime").toString())?sdfs.parse(tVehcertUploadLog.getParams().get("endTime").toString()+" 23:59:59"):"") );如何在没有.leftJoin(TVehcert.class, TVehcert::getVehId, TVehcertUploadLog::getVehId)的情况下也不使用insql方法的情况下再加一个联表查询
时间: 2024-01-21 13:16:11 浏览: 92
如果你不想使用 `leftJoin` 和 `inSql` 方法,你可以使用子查询来进行关联查询。即先查询需要关联的表,然后将查询结果作为条件进行主查询。具体实现如下:
```java
QueryWrapper<TVehcertUploadLog> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(tVehcertUploadLog.getVin()), "t_vin", tVehcertUploadLog.getVin())
.eq(StringUtils.isNotBlank(tVehcertUploadLog.getVehWzhgzbh()), "t_veh_wzhgzbh", tVehcertUploadLog.getVehWzhgzbh())
.like(StringUtils.isNotBlank(tVehcertUploadLog.getBz()), "t_bz", tVehcertUploadLog.getBz())
.eq(StringUtils.isNotBlank(tVehcertUploadLog.getIsValid()), "t_is_valid", tVehcertUploadLog.getIsValid())
.eq(StringUtils.isNotBlank(tVehcertUploadLog.getIsSample()), "t_is_sample", tVehcertUploadLog.getIsSample())
.eq(StringUtils.isNotBlank(tVehcertUploadLog.getCreateBy()), "t_create_by", tVehcertUploadLog.getCreateBy())
.ge(tVehcertUploadLog.getParams().containsKey("startTime") && StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("startTime").toString()), "t_up_date", tVehcertUploadLog.getParams().containsKey("startTime") && StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("startTime").toString()) ? sdf.parse(tVehcertUploadLog.getParams().get("startTime").toString()) : "")
.le(tVehcertUploadLog.getParams().containsKey("endTime") && StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("endTime").toString()), "t_up_date", tVehcertUploadLog.getParams().containsKey("endTime") && StringUtils.isNotEmpty(tVehcertUploadLog.getParams().get("endTime").toString()) ? sdfs.parse(tVehcertUploadLog.getParams().get("endTime").toString() + " 23:59:59") : "");
// 子查询
QueryWrapper<TVehcert> subWrapper = new QueryWrapper<>();
subWrapper.select("t_id", "t_veh_id", "t_veh_type", "t_veh_model", "t_vin", "t_electric", "t_fuel_type", "t_fuel_consumption", "t_engine_capacity", "t_engine_no", "t_gearbox_type", "t_drive_mode", "t_seat_number", "t_axle_number", "t_tire_number", "t_gross_mass", "t_unladen_mass", "t_total_mass", "t_length", "t_width", "t_height", "t_wheel_base", "t_qltgg", "t_hdzk", "t_zczbzl", "t_zdzzl", "t_zczl", "t_zgcs", "t_jsszcrs", "t_zj", "t_zzl", "t_zqyzzl", "t_zhkg", "t_zjzgl", "t_rlsbjg", "t_scdwmc", "t_scqydz", "t_zzcmc", "t_zzcxdh", "t_zzcxdz", "t_zzcsyr", "t_zzcsyrdh", "t_zzcsyrdz", "t_zzcsyrzjlx", "t_zzcsyrzjhm", "t_zzcsyrzjyz", "t_zzxzqh", "t_zzjgdm", "t_zzyxqz", "t_zzyxqzdh", "t_zzyxqzdz", "t_zzyxqzyx", "t_zzdzyx", "t_zzglbm", "t_zzlxfs", "t_zzfax", "t_zzbz");
subWrapper.eq("t_veh_type", "2"); // 查询车辆类型为2的数据
List<TVehcert> subList = tVehcertService.list(subWrapper);
// 将查询结果作为条件进行主查询
if (subList != null && subList.size() > 0) {
List<String> vehIdList = subList.stream().map(TVehcert::getVehId).collect(Collectors.toList());
wrapper.in("t_veh_id", vehIdList);
}
List<TVehcertUploadLog> list = tVehcertUploadLogService.list(wrapper);
```
这里使用 `QueryWrapper` 来构建查询条件,先进行子查询,查询车辆类型为2的数据,然后将查询结果的 `vehId` 放到一个列表中,再将列表作为条件传入主查询中的 `in` 方法中。这样就可以完成关联查询了。
阅读全文