mybatis执行批量更新batch update 的方法(提供oracle,mysql两种写法)

oracle和mysql数据库的批量update在mybatis中配置不太一样: 

oracle数据库: 

<update id="updatebatch"  parameterType="java.util.List">

  <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">

update table_name 

    <set >

      <if test="item.status != null" >

        status = #{item.status,jdbcType=INTEGER},

      if>

    set>

    where id = #{item.id,jdbcType=BIGINT}

  foreach>

    update>

mysql数据库: 

mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true 

例如:jdbc:mysql://192.168.1.232:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true 

<update id="updatebatch"  parameterType="java.util.List">

  <foreach collection="list" item="item" index="index" open="" close="" separator=";">

update table_name 

    <set >

      <if test="item.status != null" >

        status = #{item.status,jdbcType=INTEGER},

      if>

    set>

    where id = #{item.id,jdbcType=BIGINT}

  foreach>

       update>



你可能感兴趣的:(java,mybatis,Oracle,mysql)