一、mybatis执行批量更新batch update 的方法(mysql数据库)

1、数据库连接必须配置:&allowMultiQueries=true(切记一定要加上这个属性,否则会有问题,切记!切记!切记!)
  我的配置如下:jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
2、批量修改并加判断条件(修改字段可选)
<!-- 批量更新 -->
<update id="updateMatchs" parameterType="java.util.List">
<foreach collection="matchs" item="item" index="index" open="" close="" separator=";">
update t_match
<set>
<if test="item.title !=null">
TITLE = #{item.title,jdbcType=VARCHAR},
</if>
<if test="item.homeScore !=null">
HOME_SCORE = #{item.homeScore,jdbcType=INTEGER},
</if>
<if test="item.visitScore !=null">
VISTT_SCORE = #{item.visitScore,jdbcType=INTEGER},
</if>
<if test="item.liveSource !=null">
LIVE_SOURCE = #{item.liveSource,jdbcType=VARCHAR},
</if>
<if test="item.liveURL !=null">
LIVE_URL = #{item.liveURL,jdbcType=VARCHAR},
</if>
<if test="item.isHotMatch !=null">
IS_HOT_MATCH = #{item.isHotMatch,jdbcType=VARCHAR}
</if>
</set>
where HOME_TEAM_ID = #{item.homeTeamId,jdbcType=VARCHAR} and
VISIT_TEAM_ID = #{item.visitTeamId,jdbcType=VARCHAR} and
MATCH_TIME = #{item.matchTime,jdbcType=BIGINT}
</foreach>
</update>
3、java 接口
  /**
* 批量修改赛程
*
* @param matchs
* @throws DaoException
*/
void updateMatchs(@Param(value = "matchs")List<MatchBasic> matchs);

二、mybatis执行批量更新batch update 的方法(oracle数据库)

1、批量修改并加判断条件(修改字段可选)

<update id="batchUpdateSplitSinglePickCurrency" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
UPDATE ZC_TR_MULTI_ORDER_CURRENCY
<set>
<if test="item.sysCorderCode != null">
SYS_CORDER_CODE = #{item.sysCorderCode,jdbcType=VARCHAR},
</if> <if test="item.sysPorderCode != null">
SYS_PORDER_CODE = #{item.sysPorderCode,jdbcType=VARCHAR},
</if> <if test="item.bizPorderCode != null">
BIZ_PORDER_CODE = #{item.bizPorderCode,jdbcType=VARCHAR},
</if> <if test="item.originalOrderCode != null">
ORIGINAL_ORDER_CODE = #{item.originalOrderCode,jdbcType=VARCHAR},
</if> <if test="item.splitUserId != null">
SPLIT_USER_ID = #{item.splitUserId,jdbcType=VARCHAR},
</if> <if test="item.createDate != null">
CREATE_DATE = #{item.createDate},
</if> <if test="item.updateDate != null">
UPDATE_DATE = #{item.updateDate},
</if>
</set>
where id = #{item.id,jdbcType=VARCHAR}
</foreach>
</update>

2、java接口

  /**
* @Desc : 批量更新大批量子订单详情信息
* @Author : ZRP
* @Date : 2018/1/26 15:24
*/
int batchUpdateSplitSinglePickCurrency(@Param(value = "list") List<MultiOrderCurrency> list) throws Exception;
PS:一定要注意文中标红色的地方

170829、mybatis使用oracle和mybatis中批量更新的更多相关文章

  1. Myabtis中批量更新update多字段

    在mybatis中批量更新多个字段 推荐使用如下操作: 方式1:在Dao层接口中: void updateBatch(@Param("list")List<Student&g ...

  2. 从源码的角度看 React JS 中批量更新 State 的策略(下)

    这篇文章我们继续从源码的角度学习 React JS 中的批量更新 State 的策略,供我们继续深入学习研究 React 之用. 前置文章列表 深入理解 React JS 中的 setState 从源 ...

  3. Mybatis对oracle数据库进行foreach批量插入操作

    MySQL支持的语法 INSERT INTO `tableX` ( `a`, `b`, `c`, `d`, `e` ) VALUES <foreach collection ="lis ...

  4. Mybatis 针对ORACLE和MYSQL的批量插入与多参数批量删除

    今天利用Mybatis的<for each>标签做oracle的批量插入数据时,发现和MySQL数据库有区别.在此记录下,以防之后再踩坑. 一.批量插入: 1.controller: /* ...

  5. mysql批量update更新,mybatis中批量更新操作

    在日常开发中,有时候会遇到批量更新操作,这时候最普通的写法就是循环遍历,然后一条一条地进行update操作.但是不管是在服务端进行遍历,还是在sql代码中进行遍历,都很耗费资源,而且性能比较差,容易造 ...

  6. mybatis中批量更新的问题

    问题:使用mybatis在执批量更新操作时,一直报错执行失败 解决方法: 首先打印了SQL语句,发现SQL语句拿出来执行没问题,也可以批量执行.SQL没问题,应该是配置的问题. 在网上查询和很多资料, ...

  7. .Net中批量更新或添加数据

    方法一:使用SqlBulkCopy实现批量更新或添加数据. SqlBulkCopy类一般只能用来将数据批量插入打数据库中,如果数据表中设置了主键,出现重复数据的话会报错,如果没有设置主键,那么将会添加 ...

  8. 从源码的角度看 React JS 中批量更新 State 的策略(上)

    在之前的文章「深入理解 React JS 中的 setState」与 「从源码的角度再看 React JS 中的 setState」 中,我们分别看到了 React JS 中 setState 的异步 ...

  9. oracle 在xml中批量插入,批量修改及多组条件查询

    最近公司用ibatis开发项目,本来可以用存储过程处理批量插入,批量修改及多组条件查询:但由于使用模块相对较小,暂时就在xml中配置,以前没有在xml做过类似处理,有必要记录一下:好了,代码如下: & ...

随机推荐

  1. Java:大文件拆分工具

    java大文件拆分工具(过滤掉表头) import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File ...

  2. windows多线程同步互斥--总结

    我的windows多线程系列文章: windows多线程--原子操作 windows多线程同步--事件 windows多线程同步--互斥量 windows多线程同步--临界区 windows多线程同步 ...

  3. angularjs drag and drop

    angular-dragula Drag and drop so simple it hurts 480 live demo angular-drag-and-drop-lists Angular d ...

  4. 内核编译之vmlinuz vmlinux system.map initrd

    一.vmlinuz  vmlinuz是可引导的.压缩的内核.“vm”代表“Virtual Memory”.Linux 支持虚拟内存,不像老的操作系统比如DOS有640KB内存的限制.Linux能够使用 ...

  5. python排序出现的问题以及解决方案

    对某个文件夹中的文件重命名的时候,发现有些文件丢失,代码如下: #coding=gbk # Findthe every dir, if 01.rm exist in it, then rename i ...

  6. Effective Java 第三版——56. 为所有已公开的API元素编写文档注释

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  7. BigDecimal乘法

    BigDecimal result = new BigDecimal(doubleValue).multiply(factor2); public class Payment { BigDecimal ...

  8. Atitit 数据库视图与表的wrap与层级查询规范

    Atitit 数据库视图与表的wrap与层级查询规范 1.1. Join层..连接各个表,以及显示各个底层字段1 1.2. 统计层1 1.3. 格式化层1 1.1. Join层..连接各个表,以及显示 ...

  9. ES Grafana

    https://github.com/trevorndodds/elasticsearch-metrics https://grafana.com/dashboards/878 https://gra ...

  10. tensorflow 笔记8:RNN、Lstm源码,训练代码输入输出,维度分析

    tensorflow 官网信息:https://www.tensorflow.org/api_docs/python/tf/contrib/rnn/BasicLSTMCell tensorflow 版 ...