1、mybatis批量插入数据信息
<insert id="insertMoreEmpOrg" parameterType="java.util.List"> INSERT INTO hr_emp_org(EMPID,ORGID,ISMAN, UPDATETIME) VALUES <foreach collection="empOrgList" item="item" separator=","> (#{item.empid},#{item.orgid},#{item.isman},#{item.updatetime}) </foreach> </insert>
2、mybatis批量修改数据信息
<update id="updateMoreEmpJob" parameterType="java.util.List"> update hr_emp_job <trim prefix="set" suffixOverrides=","> <trim prefix="INDATE =case EMPID" suffix="end,"> <foreach collection="empJobList" item="item" index="index"> <if test="item.indate != null"> when #{item.empid} then #{item.indate} </if> </foreach> </trim> 。。。。。 <trim prefix="ORGID =case EMPID" suffix="end,"> <foreach collection="empJobList" item="item" index="index"> <if test="item.orgid != null"> when #{item.empid} then #{item.orgid} </if> </foreach> </trim> </trim> where EMPID in <foreach collection="empJobList" item="item" open="(" separator="," close=")"> #{item.empid} </foreach> </update>
3、mybatis批量修改数据信息(联合主键)
<update id="updateMoreEmpOrg" parameterType="java.util.List"> update hr_emp_org <trim prefix="set" suffixOverrides=","> <trim prefix="ISMAN = CASE" suffix="end,"> <foreach collection="empOrgList" item="item" index="index"> <if test="item.isman != null"> when EMPID = #{item.empid} and ORGID = #{item.orgid} then #{item.isman} </if> </foreach> </trim> <trim prefix="UPDATETIME = CASE" suffix="end,"> <foreach collection="empOrgList" item="item" index="index"> <if test="item.updatetime != null"> when EMPID = #{item.empid} and ORGID = #{item.orgid}then #{item.updatetime} </if> </foreach> </trim> </trim> where EMPID in <foreach collection="empOrgList" item="item" open="(" separator="," close=")"> #{item.empid} </foreach>