mybatis批量插入,批量更新
阿新 • • 發佈:2020-12-24
批量插入
<!--批量插入--> <insert id="batchInsert"> insert into t_ingco_trade_lithium_electric_product ( product_no, li_e_product_no, transpor_report_number, msds, transpor_report_number_path, msds_path, un_test_report_path, drop_test_report_path, certificate_identification_number, certificate_identification_name, certificate_identification_name_en, lithium_content, rated_power, version_no, del_flag, create_by, create_date, update_by, update_date ) VALUES <foreach collection="list" item="item" separator=","> ( #{item.productNo}, #{item.liEProductNo}, #{item.transporReportNumber}, #{item.msds}, #{item.transporReportNumberPath}, #{item.msdsPath}, #{item.unTestReportPath}, #{item.dropTestReportPath}, #{item.certificateIdentificationNumber}, #{item.certificateIdentificationName}, #{item.certificateIdentificationNameEn}, #{item.lithiumContent}, #{item.ratedPower}, 1, 0, #{item.createBy}, #{item.createDate}, #{item.updateBy}, #{item.updateDate} ) </foreach> </insert>
批量插入只需要用到
批量更新
<!--批量更新報告路徑--> <update id="UpdateTransporReportNumberPath"> update t_ingco_trade_lithium_electric_product set transpor_report_number_path = <foreach collection="list" item="item" open="case transpor_report_number" close="else transpor_report_number end"> when #{item.transporReportNumber} then #{item.transporReportNumberPath} </foreach> ,version_no = version_no + 1, update_by = <foreach collection="list" item="item" open="case transpor_report_number" close="else update_by end"> when #{item.transporReportNumber} then #{item.updateBy} </foreach> ,update_date = <foreach collection="list" item="item" open="case transpor_report_number" close="else update_date end"> when #{item.transporReportNumber} then #{item.updateDate} </foreach> where <foreach collection="list" item="item" open="(" close=")" separator="or"> transpor_report_number = #{item.transporReportNumber} </foreach> </update>
使用