mapper文件中forearch报Unknown column ‘2‘ in ‘where clause‘

问题描述

提示:mapper.xml文件的错误Unknown column '2' in 'where clause'

运行如下代码是报错,报错的SQL语句,复制到Navicat中运行,结果正常,但在springboot+mybatis-plus项目中却报如上错误

    <select id="selectFileInfoListByOrg" parameterType="com.jhunicom.project.country.domain.FileInfo" resultMap="FileInfoResult">
        select f.id as id,f.`name` as `name`,f.file_path as file_path,f.url as url,f.user_id as user_id,f.user_name as user_name,f.update_by as update_by,f.update_time as update_time,f.create_time as create_time 
        from file_info f
        RIGHT JOIN sys_user su
        ON f.user_id = su.user_id
        <where>
            su.dept_id in 
            <foreach item="orgID" index="index" collection="orgIDList" open="(" separator="," close=")">
                #{orgID}
            </foreach>
        </where>
    </select>

解决方案:

需要在<forearch>\标签之前添加<if>判断即可

    <select id="selectFileInfoListByOrg" parameterType="com.jhunicom.project.country.domain.FileInfo" resultMap="FileInfoResult">
        select f.id as id,f.`name` as `name`,f.file_path as file_path,f.url as url,f.user_id as user_id,f.user_name as user_name,f.update_by as update_by,f.update_time as update_time,f.create_time as create_time 
        from file_info f
        RIGHT JOIN sys_user su
        ON f.user_id = su.user_id
        <where>
        <if test="orgIDList != null">
            su.dept_id in 
            <foreach item="orgID" index="index" collection="orgIDList" open="(" separator="," close=")">
                #{orgID}
            </foreach>
        </if>
        </where>
    </select>

补充

后续发现把代码还原为最初的没有if判断的代码后,仍然可以用。。。有点奇怪

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值