首页 > 数据库 >Mysql Mybatis 批量修改数据

Mysql Mybatis 批量修改数据

时间:2023-04-22 21:00:31浏览次数:52  
标签:批量 2203220000003867 when item Mysql Mybatis 2203220000003869 2203220000003868 id

Mysql Mybatis 批量修改数据

Mapper

Integer updateListPO(List<ProjectQuotationItemPO> upateList);

方法一:

<update id="updateListPO">
<foreach collection="list" separator=";" item="item">
UPDATE project_quotation_item
SET product_num = #{item.productNum},
product_price_total = #{item.productPriceTotal},
product_price_wttax = #{item.productPriceWttax},
certificate = #{item.certificate},
deliver_date = #{item.deliverDate},
product_brand = #{item.productBrand},
producer = #{item.producer},
exp = #{item.exp},
is_deleted = #{item.isDeleted},
remark = #{item.remark},
substitute_type = #{item.substituteType},
quotation_status = #{item.quotationStatus}
WHERE
id = #{item.id}
</foreach>
</update>

需要在SQL连接的URL添加 allowMultiQueries=true 但是根据不同的Mysql版本或者是其他环境因素,可能还是会执行失败。

方法二:

<update id="updateListPO">
<!-- 优化后的逻辑 -->
update project_quotation_item
<set>
<trim prefix="product_num = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.productNum}
</foreach>
</trim>
<trim prefix="product_price_total = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.productPriceTotal}
</foreach>
</trim>
<trim prefix="product_price_wttax = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.productPriceWttax}
</foreach>
</trim>
<trim prefix="certificate = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.certificate}
</foreach>
</trim>
<trim prefix="deliver_date = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.deliverDate}
</foreach>
</trim>
<trim prefix="product_brand = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.productBrand}
</foreach>
</trim>
<trim prefix="producer = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.producer}
</foreach>
</trim>
<trim prefix="exp = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.exp}
</foreach>
</trim>
<trim prefix="is_deleted = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.isDeleted}
</foreach>
</trim>
<trim prefix="remark = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.remark}
</foreach>
</trim>
<trim prefix="substitute_type = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.substituteType}
</foreach>
</trim>
<trim prefix="quotation_status = case" suffix="end,">
<foreach collection="list" item="item">
when id=#{item.id} then #{item.quotationStatus}
</foreach>
</trim>
</set>
<where>
id in
<foreach collection="list" separator="," item="item" open="(" close=")">
#{item.id}
</foreach>
</where>
</update>

拼接处的SQL语句

update project_quotation_item
SET product_num = case when id=2203220000003867 then 101

when id=2203220000003868 then 10

when id=2203220000003869 then 20 end,
product_price_total = case when id=2203220000003867 then 1111

when id=2203220000003868 then 220

when id=2203220000003869 then 660 end,
product_price_wttax = case when id=2203220000003867 then 11

when id=2203220000003868 then 22

when id=2203220000003869 then 33 end,
certificate = case when id=2203220000003867 then "11"

when id=2203220000003868 then "22"

when id=2203220000003869 then "33" end,
deliver_date = case when id=2203220000003867 then 11

when id=2203220000003868 then 22

when id=2203220000003869 then 33 end,
product_brand = case when id=2203220000003867 then "11"

when id=2203220000003868 then "22"

when id=2203220000003869 then "33" end,
producer = case when id=2203220000003867 then "11"

when id=2203220000003868 then "22"

when id=2203220000003869 then "33" end,
exp = case when id=2203220000003867 then 11

when id=2203220000003868 then 22

when id=2203220000003869 then 33 end,
is_deleted = case when id=2203220000003867 then 0

when id=2203220000003868 then 0

when id=2203220000003869 then 0 end,
remark = case when id=2203220000003867 then null

when id=2203220000003868 then null

when id=2203220000003869 then null end,
substitute_type = case when id=2203220000003867 then "11"

when id=2203220000003868 then "22"

when id=2203220000003869 then "33" end,
quotation_status = case when id=2203220000003867 then 2

when id=2203220000003868 then 2

when id=2203220000003869 then 2 end
WHERE id in
(
2203220000003867
,
2203220000003868
,
2203220000003869
)

标签:批量,2203220000003867,when,item,Mysql,Mybatis,2203220000003869,2203220000003868,id
From: https://www.cnblogs.com/chuangsi/p/17343926.html

相关文章

  • Loading class `com.mysql.jdbc.Driver'. 问题
     解决Loadingclass`com.mysql.jdbc.Driver'.Thisisdeprecated.Thenewdriverclassis`com.mysql.cj.jdbc.Driver'.ThedriverisautomaticallyregisteredviatheSPIandmanualloadingofthedriverclassisgenerallyunnecessary.警告问题错误提示:Loadi......
  • MySQL读写分离ProxySQL安装部署
    ProxySQL简介ProxySQL为MySQL的中间件,其有两个版本官方版和percona版,percona版是基于官方版基础上修改而来。ProxySQL是由C++语言开发,轻量级但性能优异(支持处理千亿级数据),其具有中间件所需要的绝大多数功能,如:多种方式的读写分离定制基于用户、基于schema、基于语言的规则对SQL语句......
  • 干货分享:用ChatGPT调教批量出Midjourney咒语,出图效率Nice ,附资料。
    Prompts就是AI绘图的核心竞争力。您是不是觉得用Midjourney生成的图不够完美?又让ChatGPT去生成Prompt,然后效果还不理想?其实ChatGPT你给他投喂资料后,经过调教的ChatGPT,生成的Prompt效果会很不错。文末附《一整套MidJourney指令大全》+《ChatGPTprompt指令大全》资料先看测试......
  • mybatis-plus使用聚合函数报错---------net.sf.jsqlparser.parser.ParseException: En
    错误日志: Causedby:net.sf.jsqlparser.parser.ParseException:Encounteredunexpectedtoken:"with""WITH"atline62,column20.Wasexpectingoneof:"&""::"";""<<&q......
  • mybatis总结
    mybatis总结 https://blog.csdn.net/qq_47540091/article/details/123446973Mybatisin逗号分隔字符串 <updateid="softDel"parameterType="String">SELECT*FROMstudyWHEREidin<foreachitem="item"index="inde......
  • mysql获取当前年月 mysql中replace into用法
    mysql获取当前年月 //1.获取年月日时分秒selectSYSDATE()AS'年月日时分秒';2020-07-0216:36:17//2.获取(年月日)selectDATE(CURDATE())as'年月日';selectCURDATE()as'年月日';selectcurrent_dateAS'年月日';2020-07-02//3.获取(时分秒):......
  • mybatisplus更新字段为null怎么处理?
    mybatisplus更新字段为null怎么处理?  /***主键*/@TableId(type=IdType.ASSIGN_ID)@ApiModelProperty(value="主键")privateStringid;/***企业号*/@ApiModelProperty(value="企业号")@TableFi......
  • mybatisplus中update用法 update多个字段 mybatis-plus指定实体类字段不查询 mybatis-
     @OverridepublicbooleanupdateRiskverificationFlag(StringacptracctName){BmsBillRiskverificationbbr=newBmsBillRiskverification();bbr.setWarnflag("1");bbr.setUpdateBy("job");intnum=bill......
  • mysql综合练习题
    作业1第一题D错误。别名有空格要用“”都引起来第三题别名和之前的列名都可以使用作业2SELECT*FROMempSELECT*FROMdeptSELECT*FROMsalgrade--作业2--2.查看dept表和emp表的结构DESCdept;DESCemp;--3.1显示所有部门的名称SELECTdnameFROMd......
  • JDBC批量插入大量数据(高性能)
    rewriteBatchedStatements使用jdbc批量插入功能,rewriteBatchedStatements参数必不可少。对插入而言,所谓的rewrite其实就是将一批插入拼接成insertintoxxxvalues(a),(b),(c)...这样一条语句的形式然后执行,这样一来跟拼接sql的效果是一样的。但是此参数默认false,即便使用......