一开始使用工具类将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> 这种格式后, 一切就正常了。