ibatis批量插入、修改、刪除
<parameterMap class="com.entity.File" id="fileMap">
<parameter property="fileId" />
<parameter property="title" />
<parameter property="brief" />
<parameter property="content" />
<parameter property="url" />
</parameterMap>
批量插入
<span style="white-space:pre"> </span><insert id="insertList" parameterClass="java.util.List"> <span style="white-space:pre"> </span>insert into files (fileID,title,brief,content,url) values <span style="white-space:pre"> </span><iterate conjunction=","> <span style="white-space:pre"> </span>(#files[].fileId#,#files[].title#,#files[].brief#,#files[].content#,#files[].url#) <span style="white-space:pre"> </span></iterate> <span style="white-space:pre"> </span></insert>
批量刪除
<!-- 批量刪除一 --> <delete id="delList" parameterClass="java.util.List"> delete from files <iterate prepend="where" conjunction="OR"> fileId = #fileIds[]# </iterate> </delete> <!-- 批量刪除二 --> <delete id="delList" parameterClass="java.util.List"> delete from files where fileId in <iterate open="(" close=")" conjunction=","> #fileIds[]# </iterate> </delete>
批量修改
<update id="updateFiles" parameterClass="java.util.HashMap">
update files set title = #files.title# where fileId in
<iterate property="fileIds" open="(" close=")" conjunction=",">
#fileIds[]#
</iterate>
</update>
注意:如果使用的List只是Map的屬性,請用property