MyBatis 批量插入List<T> 和批量更新List<T>

Mapper 接口定义:

// 批量新增
	void batchInsert(List<T> list);

 

Mapper.xml 文件

 <!-- 批量新增  -->
  <insert id="batchInsert" parameterType="java.util.List">
    			insert into SYS_ROLE_PRIVILEGE
    			(SID, ROLE_SID, PRIVILEGE_SID)
    			values
    			<foreach collection="list" item="item" index="index" separator=",">
    				(
    					#{item.sid},
    					#{item.roleSid},
    					#{item.privilegeSid}
    				)
    		     </foreach>		
    </insert>    

 

Mapper 接口定义

 // 方法梳理
    void batchUpdate(List<FileInfo> list);

Mapper.xml 文件

	<!-- 批量更新  -->
	<update id="batchUpdate" parameterType="java.util.List">
		 <foreach collection="list" item="item" index="index" open="" close="" separator=";">
			 	update ucas_file_info
			<set>
				<if test="item.archSid != null">
					arch_sid = #{item.archSid,jdbcType=VARCHAR},
				</if>
				<if test="item.unitProjSid != null">
					unit_proj_sid = #{item.unitProjSid,jdbcType=VARCHAR},
				</if>
				<if test="item.individualProjSid != null">
					individual_proj_sid =
					#{item.individualProjSid,jdbcType=VARCHAR},
				</if>
				<if test="item.engProjSid != null">
					eng_proj_sid = #{item.engProjSid,jdbcType=VARCHAR},
				</if>
				<if test="item.fileNo != null">
					file_no = #{item.fileNo,jdbcType=VARCHAR},
				</if>
				<if test="item.archFileNo != null">
					arch_file_no = #{item.archFileNo,jdbcType=VARCHAR},
				</if>
				<if test="item.fileId != null">
					file_id = #{item.fileId,jdbcType=VARCHAR},
				</if>
				<if test="item.oldFileId != null">
					old_file_id = #{item.oldFileId,jdbcType=VARCHAR},
				</if>
				<if test="item.fileTitle != null">
					file_title = #{item.fileTitle,jdbcType=VARCHAR},
				</if>
				<if test="item.responsibility != null">
					responsibility = #{item.responsibility,jdbcType=VARCHAR},
				</if>
				<if test="item.fileImageNo != null">
					file_image_no = #{item.fileImageNo,jdbcType=VARCHAR},
				</if>
				<if test="item.manuscriptCode != null">
					manuscript_code = #{item.manuscriptCode,jdbcType=VARCHAR},
				</if>
				<if test="item.storageTypeCode != null">
					storage_type_code = #{item.storageTypeCode,jdbcType=VARCHAR},
				</if>
				<if test="item.securityLevelCode != null">
					security_level_code =
					#{item.securityLevelCode,jdbcType=VARCHAR},
				</if>
				<if test="item.openStatus != null">
					open_status = #{item.openStatus,jdbcType=VARCHAR},
				</if>
				<if test="item.fileTypeCode != null">
					file_type_code = #{item.fileTypeCode,jdbcType=VARCHAR},
				</if>
				<if test="item.startDate != null">
					start_date = #{item.startDate,jdbcType=TIMESTAMP},
				</if>
				<if test="item.endDate != null">
					end_date = #{item.endDate,jdbcType=TIMESTAMP},
				</if>
				<if test="item.pageNo != null">
					page_no = #{item.pageNo,jdbcType=VARCHAR},
				</if>
				<if test="item.textNums != null">
					text_nums = #{item.textNums,jdbcType=INTEGER},
				</if>
				<if test="item.drawNums != null">
					draw_nums = #{item.drawNums,jdbcType=INTEGER},
				</if>
				<if test="item.baseNums != null">
					base_nums = #{item.baseNums,jdbcType=INTEGER},
				</if>
				<if test="item.photoNums != null">
					photo_nums = #{item.photoNums,jdbcType=INTEGER},
				</if>
				<if test="item.negativeNums != null">
					negative_nums = #{item.negativeNums,jdbcType=INTEGER},
				</if>
				<if test="item.mediaTypeCode != null">
					media_type_code = #{item.mediaTypeCode,jdbcType=VARCHAR},
				</if>
				<if test="item.specCode != null">
					spec_code = #{item.specCode,jdbcType=VARCHAR},
				</if>
				<if test="item.efileInfo != null">
					efile_info = #{item.efileInfo,jdbcType=VARCHAR},
				</if>
				<if test="item.fileHierarchy != null">
					file_hierarchy = #{item.fileHierarchy,jdbcType=VARCHAR},
				</if>
				<if test="item.recordType != null">
					record_type = #{item.recordType,jdbcType=VARCHAR},
				</if>
				<if test="item.note != null">
					note = #{item.note,jdbcType=VARCHAR},
				</if>
				<if test="item.createdBy != null">
					created_by = #{item.createdBy,jdbcType=VARCHAR},
				</if>
				<if test="item.createdDt != null">
					created_dt = #{item.createdDt,jdbcType=TIMESTAMP},
				</if>
				<if test="item.updatedBy != null">
					updated_by = #{item.updatedBy,jdbcType=VARCHAR},
				</if>
				<if test="item.updatedDt != null">
					updated_dt = #{item.updatedDt,jdbcType=TIMESTAMP},
				</if>
				<if test="item.pdfCreatedFlag != null">
					pdf_created_flag = #{item.pdfCreatedFlag,jdbcType=INTEGER},
				</if>
				<if test="item.pdfPath != null">
					pdf_path = #{item.pdfPath,jdbcType=VARCHAR},
				</if>
				<if test="item.pdfFilename != null">
					pdf_filename = #{item.pdfFilename,jdbcType=VARCHAR},
				</if>
				<if test="item.pdfCreatedDt != null">
					pdf_created_dt = #{item.pdfCreatedDt,jdbcType=TIMESTAMP},
				</if>
				<if test="item.deleteFlag != null">
					delete_flag = #{item.deleteFlag,jdbcType=VARCHAR},
				</if>
			</set>
			where sid = #{item.sid,jdbcType=VARCHAR}
		 </foreach>
	</update>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值