Mybatis批量新增、更新、刪除

1.批量刪除

<delete id="batchDel" parameterType="java.util.List">
		delete from notice where id in
		<foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
			#{item}
		</foreach>
</delete>
<!-- 參數類型是List<String>,id集合 -->

2.批量更新

<update id="batchUpdate" parameterType="java.util.List">
		<foreach collection="list" item="item" index="index" open="" close="" separator=";">
		update notice
		<set>
			title = #{item.title}, content = #{item.content}
		</set>
		where id = #{item.id}
		</foreach>
</update>
<!-- 參數類型是List<Notice>,實體集合 -->

3. 批量新增

<insert id="batchSave" parameterType="java.util.List">
		insert into notice(title,content) values
		<foreach collection="list" item="item" index="index" separator=",">
			(#{item.title},#{item.content})
		</foreach>
</insert>
<!-- 參數類型是List<Notice>,實體集合 -->
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章