mybatis foreach in查询语句 关于逗号 空值处理问题

来源:互联网 发布:华硕淘宝官方旗舰店 编辑:程序博客网 时间:2024/06/04 17:41

原查询代码:


Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax;

。。。。。。。。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ‘group by mach_id,code
) d1,
(
select mach_id,sum(price) as total_price, m1’ at line 27
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

最终处理:
加上 machList的长度判断即可
如果machIdList 以逗号输入的话
machGoodsDaySale.getMachIdList().split(“,”)
得到的数组长度将是为0 ,多个逗号连续的也是一样的

        <!-- 多个专柜 -->        <if test="machList != null and machList != '' and machList.length > 0">            AND m1.code in             <foreach collection="machList" index="index" item="item" open="(" separator="," close=")">                     #{item}             </foreach>         </if>
阅读全文
0 0
原创粉丝点击