oracle和mysql数据库的批量update在mybatis中的配置

来源:互联网 发布:淘宝如何找人工客服 编辑:程序博客网 时间:2024/05/20 14:39

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

oracle数据库:
1、一次执行多条SQL语句

        <update id="department.batchSort" parameterType="List">             begin            <foreach collection="list" item="item" index="index" separator=";">                      update base_department                       <set>                        <if test="item.sort !=null">                            sort=${item.sort},                        </if>                        <if test="item.name!=null">                            name=${item.name},                        </if>                    </set>                    where id = ${item.id}             </foreach>               ;end;        </update>
2、这种方式修改的字段值都是一样的。
    <update id="department.batchSort" parameterType="List">            update  update base_department             <set>                sort=${item.sort},                name=${item.name},            </set>           where id in             <foreach collection="list" index="index" item="item" open="("separator=","close=")">                #{item.id}            </foreach>  </update>

注意:set语句之后一定别忘记加逗号

mysql数据库:

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

例如:jdbc:mysql://127.0.0.1:3306/db_cas?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true

阅读全文
0 0
原创粉丝点击