一、mapper接口
/** * 根據劇典id list查詢劇典 */ public List<Drama> selectByIds(@Param("dramaIds")List<Long> dramaIds);
二、mapper.xml文件
<!-- 根據劇典id list查詢劇典 --> <select id="selectByIds" resultMap="DramaImageResultMap"> select * from drama where drama_id in <foreach collection="dramaIds" item="dramaId" open="(" close=")" separator=","> #{dramaId} </foreach> </select>
數組參數
//接口方法 ArrayList<User> selectByIds(Integer [] ids); //xml映射文件 <select id="selectByIds" resultMap="BaseResultMap"> select * from user where id in <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach> </select>
List參數
//接口方法 ArrayList<User> selectByIds(List<Integer> ids); //xml映射文件 <select id="selectByIds" resultMap="BaseResultMap"> Select <include refid="Base_Column_List" /> from jria where ID in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach> </select>