<insert id="addUserNoKey" parameterType="User">
insert into user(userName,userPwd) values(#{userName},#{userPwd})
</insert>java
<insert id="addUserHasKey1" parameterType="user">
<selectKey keyProperty="id" order="AFTER" resultType="int">
select LAST_INSERT_ID() as id
</selectKey>
insert into user(userName,userPwd) values(#{userName},#{userPwd})
</insert>數組
Oracle 狀況it
<selectKey resultType="int" order="BEFORE" keyProperty="id">
SELECT LOGS_SEQ.nextval AS ID FROM DUAL
</selectKey>io
<insert id="addUserHasKey2" parameterType="user" useGeneratedKeys="true"keyProperty="id">
insert into user(userName,userPwd) values(#{userName},#{userPwd})
</insert>擴展
<insert id="addUserBatch" parameterType="list" >
insert into user(user_name,user_pwd) values
<foreach collection="list" item="item" separator=",">
(#{item.userName},#{item.userPwd})
</foreach>
</insert>配置
<!-- 更新單條 -->
<update id="updateUser" parameterType="User">
update user set userName=#{userName} ,userPwd=#{userPwd} where id=#{id}
</update>date
<update id="updateUserBatch" parameterType="java.util.Map">
update user set userPwd=#{pwd} where id in
<foreach collection="ids" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>foreach
<delete id="delUserById" parameterType="int">
delete from user where id=#{id}
</delete>select
<delete id="delUserBatch" parameterType="java.util.Map">
delete from user where id in
<foreach collection="ids" item="item" open="(" separator="," close=")"index="index">
#{item}
</foreach>
</delete>next
或下列形式,入參爲數組類型
<delete id="deleteUserBatch2" > delete from user where id in <foreach collection="array" item="item" open="(" separator="," close=")"> #{item} </foreach> </delete>