Mybatis批量删除
注意foreach中的collection,数组是array、list集合是list、
数组:
// void deleteClassBatchById(int[] idList);
<delete id="deleteClassBatchById" parameterType="int">
DELETE FROM classes WHERE Id in
<foreach collection="array" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
list集合:
// void deleteDateById(List<FastDFSModel> deleteList);
<delete id="deleteDateById" parameterType="java.util.List">
delete from T_FASTDFS_PATH t where t.path_id in
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item.pathId,jdbcType=VARCHAR}
</foreach>
</delete>
map:
//map的属性集
Map<String,String[]> rooms = new HashMap<String, String[]>();
roomsId.put("roomsId",id);
//mapper接口
int deleteRoomById(Map<String, String[]> rooms);
//mapper.xml
<delete id="deleteRoomById" parameterType="map">
DELETE FROM t_room WHERE Id in
<foreach collection="roomsId" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</delete>