旧的issue讲的不对,测了一下和动态表名没关系,就是单纯的sql拼错 https://github.com/baomidou/mybatis-plus/issues/4082

当前使用版本

<!--mybatis plus-->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.4.3.4</version>
 </dependency>

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

LambdaQueryChainWrapper<MpDemo> queryChainWrapper = ChainWrappers.lambdaQueryChain(mpDemoMapper)
                .select(MpDemo::getId, MpDemo::getName)
                .eq(MpDemo::getDataStatus, 0);
Long count = queryChainWrapper.count(); //报错

报错信息

sql为:select count(id,name) from *** 报错信息为:

org.springframework.jdbc.BadSqlGrammarException: \r\n### 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 'name\n ) FROM mp_demo \n \n WHERE (data_status = 0)' at line 2\r\n### The error may exist in com/example/demo/mapper/MpDemoMapper.java (best guess)\r\n### The error may involve defaultParameterMap\r\n### The error occurred while setting parameters\r\n### SQL: SELECT COUNT(  id,name  ) FROM mp_demo     WHERE (data_status = ?)\r\n### 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 'name\n ) FROM mp_demo \n \n WHERE (data_status = 0)' at line 2\n; bad SQL grammar []; nested exception is 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 'name\n ) FROM mp_demo \n \n WHERE (data_status = 0)' at line 2

我的demo

https://github.com/kiritokun07/mp_demo

Comment From: miemieYaho

你代码的意思就是等于你在xml写select count(id,name) from ***