mybatis 批量的更新

来源:互联网 发布:广州数据恢复 24小时 编辑:程序博客网 时间:2024/05/16 13:47

1.oracle 配置

<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>

2.mysql 配置
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>                  test=${item.test}+1                </set>                where id = ${item.id}         </foreach>    </update>
0 0
原创粉丝点击