美文网首页
Spring + mybatis批量更新方法

Spring + mybatis批量更新方法

作者: 帅大叔的简书 | 来源:发表于2016-10-27 17:16 被阅读2352次

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

相关文章

网友评论

      本文标题:Spring + mybatis批量更新方法

      本文链接:https://www.haomeiwen.com/subject/tvksuttx.html