orcal 批量插入與批量修改
阿新 • • 發佈:2018-12-11
<!--批量插入--> <insert id="insertBatch" parameterType="com.deppon.tps.module.departmentbase.shared.domain.DepartmentEntity"> <!--獲取隨機生成的主鍵id--> <selectKey keyProperty="id" resultType="string" order="BEFORE"> select sys_guid() as ID from dual </selectKey> INSERT INTO t_org_department( <!--需要插入的列--> <include refid="insert_param"/> ) select sys_guid() as ID ,A.* from( <!--遍歷list迴圈插入其中--> <foreach collection="list" item="item" index="index" separator="UNION ALL" > select #{item.dept_code,jdbcType=VARCHAR}, #{item.dept_name,jdbcType=VARCHAR}, #{item.dept_attribute,jdbcType=VARCHAR} from dual </foreach> )A </insert> <!--批量修改--> <update id="updateBatch" parameterType="com.deppon.tps.module.departmentbase.shared.domain.DepartmentEntity"> UPDATE t_org_department set <foreach collection="list" item="item" index="index" separator=" " open="DEPT_CODE = CASE" close="end,"> WHEN id = #{item.id} then #{item.dept_code,jdbcType=VARCHAR} </foreach> <foreach collection="list" item="item" index="index" separator=" " open="DEPT_NAME = CASE" close="end,"> WHEN id = #{item.id} then #{item.dept_name,jdbcType=VARCHAR} </foreach> <foreach collection="list" item="item" index="index" separator=" " open="DEPT_ATTRIBUTE = CASE" close="end"> WHEN id = #{item.id} then #{item.dept_attribute,jdbcType=VARCHAR} </foreach> WHERE id IN ( <foreach collection="list" item="item" index="index" separator=","> #{item.id} </foreach> ) </update>