需求:有一个List a,包含着很多的应用id,使用这些id查找应用表中对应的应用。
首先需要把List转换为数组:a.toArray(new Integer[a.size()])
然后,foreach使用如下图斜体所示。
<select id="selectByAppIds" resultType="Integer"> SELECT DISTINCT b.app_id FROM a,b WHERE a.app_id = b.id AND b.app_id is NOT NULL AND b.app_id IN <foreach collection="array" item="appId" index = "index" open="(" close=")" separator=","> #{appId,jdbcType=INTEGER} </foreach> </select>