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

3.4.3

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

mapper.java listAandB(@Param("codeList") List codeList, @Param("aCode") String aCode);

a left join b ... where b.code in (#{codeList}) and a.code = #{aCode}

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

如果将#换成$ 转换成的实际sql 是a left join b ... where b.code in ([code1, code2]) and a.code = 'aCode'

这里不应该是[]

报错信息

Caused by: java.sql.SQLException: Cannot convert string '\xAC\xED\x00\x05sr...' from binary to utf8mb4 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy171.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:64) at com.sun.proxy.$Proxy161.query(Unknown Source) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) at com.sun.proxy.$Proxy160.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ... 63 more

Comment From: huayanYu

你这是交给原生mybatis执行的, in 里的条件要在xml里 for拼接

Comment From: ifrioct

小锅盖 @.***>于2021年11月12日 周五11:44写道:

你这是交给原生mybatis执行的, in 里的条件要在xml里 for拼接

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/baomidou/mybatis-plus/issues/4041#issuecomment-966796449, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJI5QASEO4FPVZETH2ZGS73ULSEQLANCNFSM5H34POIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

感谢这么快速回复!我拼接试一下!😄

Comment From: ifrioct

你这是交给原生mybatis执行的, in 里的条件要在xml里 for拼接

left join的问题 使用for拼接得到解决了, 但是我这里还有一条sql 使用的是下面的语法, 这条语句执行没有问题, 区别就是 单表和关联查询 还有 # $取值的区别, select a.* from a where 1=1 and a.code in (#{codeList})

Comment From: miemieYaho

百度:mybatis 入参 List xml 取值