`
beyondbn
  • 浏览: 71463 次
社区版块
存档分类
最新评论

mybatis mysql 批量update

阅读更多

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

oracle数据库:

1
2
3
4
5
6
7
8
9
10
11
<update id="batchUpdate"  parameterType="java.util.List">
      
       <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">
                update test
                <set>
                  test=${item.test}+1
                </set>
                where id = ${item.id}
       </foreach>
          
    </update>

mysql数据库:

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

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

 

 

can

?

1
2
3
4
5
6
7
8
9
10
11
<update id="batchUpdate"  parameterType="java.util.List">
      
          <foreach collection="list" item="item" index="index" open="" close="" separator=";">
                update test
                <set>
                  test=${item.test}+1
                </set>
                where id = ${item.id}
         </foreach>
          
    </update>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics