MyBatis刪除多行以及引數的傳遞
阿新 • • 發佈:2018-11-13
測試程式碼
@Test
public void deleteBookByIds(){
/*List<Long> ids = new ArrayList<>();
ids.add(8L);
ids.add(10L);
ids.add(12L);
ids.add(14L);*/
Long[] ids = {9L,11L,13L,15L};
session.delete("com.ss.dao.BookMapper.deleteBookByIds", ids);
}
mapper對映檔案,namespace為com.ss.dao.BookMapper
<delete id="deleteBookByIds" parameterType="java.lang.Long">
delete from t_book where book_id in
<!-- <foreach collection="list" item="id" open="(" close=")" separator="," > -->
<foreach collection="array" item="id" open="(" close=")" separator="," >
#{id}
</foreach>
</delete>
其中傳入的引數為集合是,<foreach>標籤的collection的值為list,傳入的引數為陣列時,collection的值為array!