mybatis批量新增,存在就更新(mysql数据库)
来源:互联网 发布:python 给字典赋值 编辑:程序博客网 时间:2024/05/16 05:36
只需要把要批量新增的实体类放到集合中,作为参数传给dao,
最关键就是Mapper文件中,直接上代码:
<insert id="batchInsert" parameterType="java.util.List">
insert into counterparty(<include refid="Base_Column_List"/>)values
<foreach collection="list" item="counterParty" index="index" separator=",">
(
#{counterParty.id,jdbcType=VARCHAR},
#{counterParty.fullName,jdbcType=VARCHAR},
#{counterParty.shortName,jdbcType=VARCHAR},
#{counterParty.initialLimit,jdbcType=VARCHAR},
#{counterParty.currencyName,jdbcType=VARCHAR},
#{counterParty.initialLimitUsd,jdbcType=VARCHAR},
#{counterParty.creditLimitAlertOne,jdbcType=VARCHAR},
#{counterParty.creditLimitAlertTwo,jdbcType=VARCHAR},
#{counterParty.creditLimitAlertThree,jdbcType=VARCHAR},
#{counterParty.closingRunTime,jdbcType=VARCHAR},
#{counterParty.operator,jdbcType=VARCHAR},
#{counterParty.uptime,jdbcType=VARCHAR},
#{counterParty.remark,jdbcType=VARCHAR}
)
</foreach>
ON DUPLICATE KEY UPDATE
full_name = VALUES(full_name),
short_name = VALUES(short_name),
initial_limit = VALUES(initial_limit),
currency = VALUES(currency),
initial_limit_usd = VALUES(initial_limit_usd),
credit_limit_alert_one = VALUES(credit_limit_alert_one),
credit_limit_alert_two = VALUES(credit_limit_alert_two),
credit_limit_alert_three = VALUES(credit_limit_alert_three),
closing_run_time = VALUES(closing_run_time),
operator = VALUES(operator),
uptime = now(3),
remark = "update"
</insert>
这样就OK了。
阅读全文
0 0
- mybatis批量新增,存在就更新(mysql数据库)
- Mysql 在 mybatis 环境下 批量新增 并 将已存在的数据更新
- MySql 存在记录就更新,不存在就新增
- MySQL新增数据,存在就更新,不存在就添加
- MyBatis批量新增、更新
- MyBatis批量新增和更新
- MyBatis批量新增和更新
- MyBatis中进行批量更新(MySQL数据库)
- mysql新增时存在更新
- mysql 存在就插入,存在就更新
- Mybatis批量更新数据库
- Mysql+Mybatis批量更新
- Mysql—实现批量插入,存在就更新,不存在就插入
- mybatis批量新增,更新的一些问题
- MyBatis oracle 批量 insert update 新增 更新
- mybatis批量和更新(mysql)
- mysql,存在就更新,不存在就插入
- MySQL存在时更新,否则新增
- angular-in-memory-web-api
- HttpURLConnection conten-type取值问题
- js-apply()
- 欢迎使用CSDN-markdown编辑器
- 二叉树
- mybatis批量新增,存在就更新(mysql数据库)
- IO流详细学习笔记
- RabbitMQ第四篇:远程调用
- hdu 1166 敌兵布阵 树状数组的运用
- 【Java】数组拷贝的三种方式
- 图像离散傅里叶变化幅度谱检测---在条形码识别中的作用
- Java过滤器与SpringMVC拦截器之间的关系与区别
- crontab处理java定时任务
- 基本类型与包装类型