Spring + mybatis批量更新方法

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

oracle数据库:

<update id="batchUpdate" parameterType="java.util.List">
     <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";"> 
              update test 
                    <set>    
                            name=#{item.name},
                            age= #{item.age} 
                    </set>  
              where id = #{item.id}  
      </foreach>         
</update>

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

&allowMultiQueries=true

例如:

jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
<update id="batchUpdate" parameterType="java.util.List">
     <foreach collection="list" item="item" index="index" open="" close="" separator=";"> 
              update test 
                    <set>    
                            name=#{item.name},
                            age= #{item.age} 
                    </set>  
              where id = #{item.id}  
      </foreach>         
</update>

转载自https://my.oschina.net/jsonavaj/blog/265112

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容