在mybatis.xml
<select id="muwbQueryCityAll" parameterType="String" resultType="MonCity">
SELECT CITY_CODE cityCode, REGION_CODE regionCode, CITY_NAME cityName, ORDER_ID orderId
FROM TB_MON_CITY_DICT where region_code in(#{regionCode}) group by REGION_CODE
</select>
TB_MON_CITY_DICT.region_code
为 int(11)
字符串区域代码 = "1,2,3,4,5,6,7,8,9,10";
当我同时使用 'in' 和 'group by' 时,返回列表的大小始终为 1。但是当我使用 '1,2,3,4,5,6,7, 8,9,10'
而不是#{regionCode}
,返回列表的大小是实际大小。
库和环境:Spring 3.1.3、MyBatis 3.1.1、MyBatis-Spring 1.1.1、MySQL 5.5
提前致谢。
日志: DEBUG [http-80-4] - 将 JDBC 连接返回到数据源 调试 [http-80-4] - 创建新的 SqlSession DEBUG [http-80-4] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4349816e] 未注册同步,因为同步未激活 DEBUG [http-80-4] - 从数据源获取 JDBC 连接 DEBUG [http-80-4] - JDBC 连接 [jdbc:mysql://115.28.11.23:3306/envmonitor, UserName=monitor@183.187.94.213, MySQL-AB JDBC Driver] 将不会由 Spring 管理 调试 [http-80-4] - ooo 使用连接 [jdbc:mysql://115.28.11.23:3306/envmonitor, UserName=monitor@183.187.94.213, MySQL-AB JDBC 驱动程序] DEBUG [http-80-4] - ==> 准备:选择a.COLL_ID作为collId,a.ITEM_VALUE1作为itemValue1,a.ITEM_VALUE2作为itemValue2,a.ITEM_VALUE3作为itemValue3,a.ITEM_VALUE4作为itemValue4,a.ITEM_VALUE5作为itemValue5 ,a.ITEM_VALUE6 作为 itemValue6,a.ITEM_VALUE7 作为 itemValue7,a.ITEM_VALUE8 作为 itemValue8,a.ITEM_VALUE9 作为 itemValue9,a.ITEM_VALUE10 作为 itemValue10 从 TB_MON_NUMERIC_REC 内部连接(从 TB_MON_NUMERIC_REC 选择 max(rec_Id) id,其中 coll_Id in(?)按 coll_Id 分组) b on a.rec_id=b.id 调试 [http-80-4] - ==> 参数:1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013(字符串) DEBUG [http-80-4] - 关闭非事务性 SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4349816e] DEBUG [http-80-4] - 将 JDBC 连接返回到数据源 muwb----------5-------------resultList.size()=1
请您参考如下方法:
由于 JDBC 的 SQL 安全注入(inject)机制,它不起作用。在底层,mybatis 查询归结为 JDBC 准备好的语句。 JDBC 准备好的语句仅用一个值替换占位符,因此只会注入(inject)第一个值。请引用SOlink了解更多详情。