mybatis批量操作
mybatis批量操作:
批量保存:
<insert id="batchInsertBeneficiary" parameterType="com.api.params.BeneficiaryParam" >insert into ins_beneficiary<trim prefix="(" suffix=")" suffixOverrides="," >id, reservation_id, channel_id, last_name, first_name, name, sex, identity_type,identity_no, identity_validate_date, benefit_order, benefit_proportion, relation,create_id, create_name, update_id, update_name</trim>VALUES<foreach collection="beneficiaryParamList" item="item" index="index" separator="," ><trim prefix="(" suffix=")" suffixOverrides="," >#{item.id,jdbcType=BIGINT}, #{item.reservationId,jdbcType=VARCHAR}, #{item.channelId,jdbcType=BIGINT},#{item.lastName,jdbcType=VARCHAR}, #{item.firstName,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR},#{item.sex,jdbcType=TINYINT}, #{item.identityType,jdbcType=TINYINT}, #{item.identityNo,jdbcType=VARCHAR},#{item.identityValidateDate,jdbcType=DATE}, #{item.benefitOrder,jdbcType=INTEGER}, #{item.benefitProportion,jdbcType=DECIMAL},#{item.relation,jdbcType=TINYINT}, #{item.createId,jdbcType=VARCHAR},#{item.createName,jdbcType=VARCHAR}, #{item.updateId,jdbcType=VARCHAR},#{item.updateName,jdbcType=VARCHAR}</trim></foreach></insert>
批量保存解析出来的语句格式为:
insert into 表名 (字段1,字段2) values (value1,value2)(value3,value4);
批量更新:
<update id="batchUpdateBeneficiary" parameterType="com.api.params.BeneficiaryParam">update ins_beneficiary<trim prefix="set" suffixOverrides=","><trim prefix="last_name =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.lastName}</foreach></trim><trim prefix="first_name =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.firstName}</foreach></trim><trim prefix="name =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.name}</foreach></trim><trim prefix="sex =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.sex}</foreach></trim><trim prefix="identity_type =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.identityType}</foreach></trim><trim prefix="identity_no =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.identityNo}</foreach></trim><trim prefix="identity_validate_date =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.identityValidateDate}</foreach></trim><trim prefix="relation =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.relation}</foreach></trim><trim prefix="benefit_order =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.benefitOrder}</foreach></trim><trim prefix="benefit_proportion =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.benefitProportion}</foreach></trim><trim prefix="update_id =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.updateId}</foreach></trim><trim prefix="update_name =case" suffix="end,"><foreach collection="beneficiaryParamList" item="item" index="index">when id=#{item.id} then #{item.updateName}</foreach></trim></trim><where><foreach collection="beneficiaryParamList" separator="or" item="item" index="index" ><trim prefix="(" suffix=")"><if test="item.id!=null and item.id!=''">id = #{item.id}</if></trim></foreach></where></update>
批量更新解析出来的语句格式为:
UPDATE ins_reservation_product_relation SET policy_amount = CASE WHEN insurance_code =? AND reservation_id =? THEN? WHEN insurance_code =? AND reservation_id =? THEN? END,policy_charge = CASE WHEN insurance_code =? AND reservation_id =? THEN? WHEN insurance_code =? AND reservation_id =? THEN? END WHERE1 = 1 AND is_delete = 0 AND (reservation_id = ?AND insurance_code = ? ) OR (reservation_id = ?AND insurance_code = ? )
转载于:https://www.cnblogs.com/super-chao/p/8358139.html
mybatis批量操作相关推荐
- Mybatis 批量操作总结
批量新增 1.方式一(常用) <!-- 批量新增--> <insert id="batchSave" parameterType="java.util. ...
- MyBatis批量操作和多参数查询
批量操作 1.批量添加元素session.insert(String string,Object o) [plain] view plaincopy public void batchInsertSt ...
- Mybatis 批量操作8种实现总结
批量新增 1.方式一(常用) <!-- 批量新增--> <insert id="batchSave" parameterType="java.util. ...
- Mybatis 批量操作(批量插入、批量更新、批量删除)总结
文章目录 一.批量插入 二.批量更新 三.批量删除 一.批量插入 <insert id="insertBatch" parameterType="java.util ...
- MyBatis批量操作报错:Parameter 'xxxList' not found. Available parameters are [list]
问题背景: 在Dao中使用MyBatis进行查询操作,参数是传的一个List:studentNameList,但是在执行查询的时候报错,具体日志如下: Shell代码 com.chenzhou.b ...
- mybatis批量操作之传入类型为数组及多个参数,使用@Parm注解完美解决
以前因为涉及到传入参数为多个的时候,一直都是将传入的参数通过键值对的方式存入Map,然后再取值,后来发现了@Param这个注解,但是也没去怎么用,后来发现涉及到传入参数不止一个时. 使用这个注解好处: ...
- MyBatis6:MyBatis集成Spring事物管理(下篇)
前言 前一篇文章<MyBatis5:MyBatis集成Spring事物管理(上篇)>复习了MyBatis的基本使用以及使用Spring管理MyBatis的事物的做法,本文的目的是在这个的基 ...
- Mybatis 面试常问问题总结(附答案)
Hibernate 简介 什么是 Hibernate? Hibernate 是一种 ORM(Object Relational Mapping) 框架,用于在 Java 对象和关系数据库之间建立某种映 ...
- java前台传多个id用什么接收_前端js传多个id 到java后台的处理方式
$("#createApplysjinfo").click(function(){ var allTableData=datagrid.bootstrapTable('getDat ...
- Mysql批量更新的一个坑-allowMultiQueries=true允许批量更新
前言 实际上,我们经常会遇到这样的需求,那就是利用Mybatis批量更新或者批量插入,但是,实际上即使Mybatis完美支持你的sql,你也得看看你说操作的数据库是否支持,而阿福,最近 ...
最新文章
- 数学表达式一键变图,CMU开发实用工具Penrose,堪称图解界LaTeX(附链接)
- [转]Python 命令行参数和getopt模块详解
- 积跬步,聚小流-------一个登录中的知识点
- Android自定义顶部栏及侧滑菜单和fragment+viewpag滑动切换的实现
- 组件化h5活动模板的实现
- javascript之嵌套函数
- 为easyui添加多条件验证
- 用DevExpress做界面开发:ASP.NET界面开发框架
- pmm 监控mysql、mongodb、系统
- Filter In Baan!
- Xib实现UICollectionView
- Notepad++汉化教程
- select函数使用细节
- 如何调用CAD命令行命令?
- 熵值法、灰色关联分析与层次分析法
- YDOOK:版权C符号:怎样在任何地方 任何位置快速输入版权符号 © 快捷键
- 《开源安全运维平台--OSSIM最佳实践》节日期间当当自营店 五折 优惠活动开始啦!...
- Halcon提取中心线
- ANSI转义序列详解
- 32位MD5加密 可用来微信加密