1:插入返回主键
<insert id="save" parameterType="map" useGeneratedKeys="true" keyPRoperty="ID" flushCache="false"> insert into table ( CODE ) values ( #{CODE} ) </insert>获取的主键方式:map.get("ID")2:批量插入 传入参数list
<insert id="save" parameterType="java.util.List" flushCache="false"> insert into table ( CODE ) values <foreach collection="list" item="item" separator=","> (#{item.CODE}) </foreach> </insert>3:批量更新 传入参数list注:需在 properties的配置文件中的URL 添加“allowMultiQueries=true”
<update id="updates" parameterType="java.util.List" flushCache="false"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update table <set> CODE =${item.CODE}, UPDATE_TIME =${item.UPDATE_TIME} </set> where ID =${item.ID} </foreach> </update>4:批量删除 传入参数数组<delete id="deleteAll" parameterType="String" flushCache="false"> delete from table where ID in <foreach item="item" index="index" collection="array" open="(" separator="," close=")"> #{item} </foreach></delete>
新闻热点
疑难解答