MyBatis的in查询查不到数据

一开始使用工具类将id的集合字段处理成字符串格式的in条件:

ids: 1,2,3,4  ===>  '1','2','3','4'     inStr

然后在mapper.xml中使用 in ( #{inStr})作为条件拼接进SQL语句

查询过程中,打印出的SQL语句是正确的,同时将该SQL放到DB工具中也可以查到数据,但是IDE的控制台打印确确实实是0条记录!!

百思不得其解

最后不得已修改mapper.xml文件:

<select id="listFocuseds" resultType="com.bootdo.liangu.backstage.domain.LgIndustryDictDO">
select `INDUSTRY_ID`,`DICT_VALUE`,`DICT_DESC`,`DICT_STATUS`,`UPDATE_TIME` from LG_INDUSTRY_DICT
<where>  
<if test="industryId != null and industryId != ''"> and INDUSTRY_ID = #{industryId} </if>
<if test="dictValue != null and dictValue != ''"> and DICT_VALUE = #{dictValue} </if>
<if test="dictDesc != null and dictDesc != ''"> and DICT_DESC = #{dictDesc} </if>
<if test="dictStatus != null and dictStatus != ''"> and DICT_STATUS = #{dictStatus} </if>
<if test="updateTime != null and updateTime != ''"> and UPDATE_TIME = #{updateTime} </if><if test="inStr != null"> and INDUSTRY_ID IN
	<foreach item="item" index="index" collection="inStr" open="(" separator=","close=")">  
		#{item}   
	</foreach>   
</if>
</where>
<choose>
    <when test="sort != null and sort.trim() != ''">
        order by ${sort} ${order}
    </when>
    <otherwise>
        order by INDUSTRY_ID desc
    </otherwise>
</choose>
<if test="offset != null and limit != null">
	 limit #{offset}, #{limit}
</if>
</select>

采用:

 <if test="inStr != null"> and INDUSTRY_ID IN
            <foreach item="item" index="index" collection="inStr"   open="(" separator="," close=")">  
                       #{item}   
             </foreach>   
</if> 这种格式后, 一切就正常了。 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值