mapper.xml文件,后台传入一个对象集合,另外如果是mysql数据库,一点在配置文件上加上&allowMultiQueries=true,这样才可以执行多条sql,以下为mysql:
<update id="batchUpdate" parameterType="java.util.List"> <foreach separator=";" index="index" item="item" collection="list" close="" open=""> update sys_group set level = #{item.level,jdbcType=INTEGER}where group_id = #{item.groupId,jdbcType=INTEGER}foreach> update>
如果是oracle数据库则写法有不同:
<update id="batchUpdateRepayPlan" parameterType="java.util.List">begin <foreach separator=";" index="index" item="item" collection="list" close="" open=""> update t_ba_repay_plan <set><if test="item.interest !=null">REPAY_INTEREST = #{item.interest,jdbcType=VARCHAR},if><if test="item.nimm !=null">REPAY_NIMM = #{item.nimm,jdbcType=CHAR}if>set> where IOU_CODE = #{item.iouCode} foreach> ;end; update>
本文转自:https://blog.csdn.net/pangliang_csdn/article/details/68945750