MyBatis 批量插入List 和批量更新List解析
不点
阅读:648
2021-03-31 16:57:38
评论:0
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>
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。