yulichang / mybatis-plus-join

支持连表查询的mybatis-plus,mybatis-plus风格的连表操作提供wrapper.leftJoin(),wrapper.rightJoin()等操作
https://yulichang.github.io/mybatis-plus-join-doc/
Apache License 2.0
971 stars 113 forks source link

这个插件很好用,请教我如何关联查询从表全部字段 #97

Closed miozus closed 4 months ago

miozus commented 5 months ago

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

1.4.8.1

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

我想要 .select("*") 这种一把梭给前端随便他怎么用,但是报错

jakarta.servlet.ServletException: Request processing failed: org.springframework.jdbc.BadSqlGrammarException: Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM formmain_0112 t LEFT JOIN dk_oa_kingdee_log t1 ON (t1.id = t.id AND' at line 1

但我查看官方文档尝试 .select(i -> true) 也给我报错

jakarta.servlet.ServletException: Request processing failed: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: mapper not find by class <Object> , add mapper and extends BaseMapper<T> or MPJBaseMapper<T>

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

迫不得已,我把每个字段都写一遍,这样

@Override
public PageUtils queryPage(Map<String, Object> params) {

    MPJLambdaWrapper<ExpenseFormEntity> wrapper = new MPJLambdaWrapper<ExpenseFormEntity>()
            .selectAll(ExpenseFormEntity.class)
            .select(
                    ServerLogEntity::getNo,
                    ServerLogEntity::getAnotherNo,
                    ServerLogEntity::getBillType,
                    ServerLogEntity::getVersion,
                    ServerLogEntity::getReceipt,
                    ServerLogEntity::getRemark,
                    ServerLogEntity::getStatus,
                    ServerLogEntity::getUpdateMember,
                    ServerLogEntity::getUpdateTime
            )
            .leftJoin(ServerLogEntity.class, ServerLogEntity::getId, ExpenseFormEntity::getId);
    IPage<JSONObject> page = expenseFormDao.selectJoinPage(
                    new Query<ExpenseFormVO>().getPage(params),
                    ExpenseFormVO.class, wrapper)
            .convert(entity -> {
                ExpenseFormVO vo = new ExpenseFormVO();
                BeanUtil.copyProperties(entity, vo, CopyOptions.create().ignoreNullValue().ignoreError().ignoreCase());
                vo.translate(vo);
                return JSONUtil.parseObj(vo.getJsonStr());
            });
    return new PageUtils(page);
}

报错信息

yulichang commented 4 months ago

https://mybatisplusjoin.com/pages/core/lambda/select/select.html

miozus commented 4 months ago

https://mybatisplusjoin.com/pages/core/lambda/select/select.html

找到了,在文档下一页,原来建议只用一次在主表,避免字段重复👌

https://mybatisplusjoin.com/pages/core/lambda/select/selectAll.html