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> 這種格式後, 一切就正常了。 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章