yulichang / mybatis-plus-join

支持连表查询的mybatis-plus,mybatis-plus风格的连表操作提供wrapper.leftJoin(),wrapper.rightJoin()等操作
https://mybatisplusjoin.com
Apache License 2.0
955 stars 111 forks source link

子查询无法运行 #129

Closed kang1097 closed 1 week ago

kang1097 commented 1 week ago

当前使用版本(必填,否则不予处理)

1.4.10

该问题是如何引起的?(确定最新版也有问题再提!!!)

where后面加了一个子查询

重现步骤(如果有就写完整)

default List getCompanyList() { MPJLambdaWrapperX query = new MPJLambdaWrapperX();

    // 字段选择
    query.selectAs(CompanyDO::getName, CompanyRespVO::getCompanyName)
            .selectAs(FarmDO::getName, CompanyRespVO::getFarmName)
            .selectAs(FarmDO::getAddress, CompanyRespVO::getFarmAddress)
            .select(CompanyDO::getCultureCount, CompanyDO::getFarmMonth, CompanyDO::getLivestockCount,
                    CompanyDO::getMaleCow, CompanyDO::getMotherCow, CompanyDO::getRemark);

    // 筛选条件:农场月份等于最大月份
    MPJLambdaWrapperX<CompanyDO> maxMonthQuery = new MPJLambdaWrapperX<>();
    maxMonthQuery.selectMax(CompanyDO::getFarmMonth);
    query.eq(CompanyDO::getFarmMonth, maxMonthQuery);

    // 连接农场表并按公司ID降序排序
    query.leftJoin(FarmDO.class, FarmDO::getId, CompanyDO::getFarmId)
            .orderByDesc(CompanyDO::getId);

    // 返回查询结果
    return selectJoinList(CompanyRespVO.class, query);
}

相当于以下SQL: SELECT t.NAME AS companyName, t1.NAME AS farmName, t1.address AS farmAddress, t.culture_count, t.farm_month, t.livestock_count, t.male_cow, t.mother_cow, t.remark -- (SELECT MAX(farm_month) FROM lsd_company) AS farmMonth FROM lsd_company t LEFT JOIN lsd_farm t1 ON ( t1.id = t.farm_id AND t1.deleted = 0 ) AND t1.tenant_id = 1 WHERE t.farmmonth = **(SELECT MAX(farm_month) FROM lsdcompany)** AND t.deleted = 0 AND t.tenant_id = 1 ORDER BY t.id DESC

报错信息

nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='ew.paramNameValuePairs.MPGENVAL1', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Cannot convert class cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX to SQL type requested due to com.mysql.cj.exceptions.WrongArgumentException - Invalid argument value: java.io.NotSerializableException

image
kang1097 commented 1 week ago

上面那个解决了😂 中间那一段改成这个样

image

还有一个问题哈,selectSub()无法识别

image

是版本太低了吗?