你的位置:首页 > 软件开发 > Java > Mybatis批量更新配置(Mysql batch update)

Mybatis批量更新配置(Mysql batch update)

发布时间:2015-10-28 15:01:42
Mybatis在Mysql批量更新中不支持BEGIN与END关键字,所以如下配置是错误的:1.<update id="batchUpdate" parameterType="java.util.List"> 2. 3. ...
Mybatis在Mysql批量更新中不支持BEGIN与END关键字,所以如下配置是错误的:1.<update id="batchUpdate" parameterType="java.util.List"> 2.    3.     <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";"> 4.        update test  5.        <set> 6.         test=${item.test}+1 7.        </set> 8.        where id = ${item.id} 9.     </foreach> 10.      11.</update>  正确做法如下: 方法一:执行多条SQL语句1.<update id="batchUpdate" parameterType="java.util.List"> 2. 3.<foreach collection="list" item="item" index="index" open="" close="" separator=";"> 4.update test  5.<set> 6.test=${item.test}+1 7.</set> 8.where id = ${item.id} 9.</foreach> 10. 11.</update>  方法二:执行一条SQL语句(建议) 写道1.<update id="batchUpdate" parameterType="java.util.List"> 2.update test set test=${item.test}+1 where id in 3.<foreach collection="list" item="item" index="index" open="(" close=")" separator=","> 4.${item.id} 5.</foreach> 6.</update> 

原标题:Mybatis批量更新配置(Mysql batch update)

关键词:MYSQL

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录