国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

批量插入、更新mapper寫(xiě)法

這篇具有很好參考價(jià)值的文章主要介紹了批量插入、更新mapper寫(xiě)法。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

批量更新

參考:https://blog.csdn.net/mianma_YAYIZI/article/details/102466672?spm=1001.2014.3001.5506

<update id="batchUpdate" parameterType="java.util.List">
    update base_supplier_purchasing_info_sap
    set updated_time = now(), update_by = 'sys',
    finance_purchase_frozen = case
    <foreach collection="list" item="item" index="index" separator=" ">
        when (supplier_code = #{item.supplierCode} and purchase_org_code = #{item.purchaseOrgCode}) then
        #{item.financePurchaseFrozen}
    </foreach>
    end where
    <foreach collection="list" index="index" item="item" separator="or">
        (supplier_code = #{item.supplierCode} and purchase_org_code = #{item.purchaseOrgCode})
    </foreach>
</update>

對(duì)應(yīng)sql文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-511362.html

update bak_supplier_finance_purchase_frozen_info
set updated_time            = now(),
    update_by               = 'sys',
    finance_purchase_frozen = case when (supplier_code = '20036982' and purchase_org_code = 'P001') then '1'  end
where (supplier_code = '20036982' and purchase_org_code = 'P001');

批量插入

<insert id="batchInsert" parameterType="java.util.List">
   insert into bak_supplier_finance_purchase_frozen_info
       (id, supplier_code, purchase_org_code, finance_purchase_frozen)
   values
   <foreach collection="list" item="item" separator=",">
       (#{item.id,jdbcType=BIGINT}, #{item.supplierCode,jdbcType=VARCHAR}, #{item.purchaseOrgCode,jdbcType=VARCHAR}, #{item.financePurchaseFrozen,jdbcType=VARCHAR})
   </foreach>
</insert>

批量更新&插入

<insert id="insertAndUpdate" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
  insert into instead_of_sending_order_relation
  (supplier_code, apply_order_no, purchase_order_no, account_direction, apply_date,
   is_delete, created_time, updated_time, created_by, updated_by) values
  <foreach collection="list" separator="," item="item">
    (#{item.supplierCode},#{item.applyOrderNo},#{item.purchaseOrderNo},#{item.accountDirection},#{item.applyDate},
    #{item.isDelete},#{item.createdTime},#{item.updatedTime},#{item.createdBy},#{item.updatedBy})
  </foreach>
    ON DUPLICATE KEY UPDATE
        supplier_code = values(supplier_code),
        apply_order_no = values(apply_order_no),
        purchase_order_no = values(purchase_order_no),
        account_direction = values(account_direction),
        apply_date = values(apply_date),
        is_delete = values(is_delete),
        created_time = values(created_time),
        updated_time = values(updated_time),
        created_by = values(created_by),
        updated_by = values(updated_by)
</insert>

查詢

 @Override
public Page<ResSupplierWhiteListVo> selectByConditions(ReqSupplierWhiteListQueryVO reqSupplierWhitelistQueryVO) {
    Page<ResSupplierWhiteListVo> resultPage = new Page<>();
    com.baomidou.mybatisplus.extension.plugins.pagination.Page<SupplierWhiteList> queryPage
            = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(reqSupplierWhitelistQueryVO.getPage(), reqSupplierWhitelistQueryVO.getSize());
    queryPage.setDesc("updated_time");
    List<SupplierWhiteList> supplierWhiteLists = supplierWhiteListMapper.selectByConditionsByPage(queryPage, reqSupplierWhitelistQueryVO);
//獲取特例名稱
Map<String, String> specialCaseMap =  categoryAttributeService.getCategoryAttribute(BizConstant.ATTRIBUTE_KEY_SUPPLIER_WHITE_LIST,  BizError.SUPPLIER_WHITE_LIST_GET_SPECIAL_CASE_CODE_FAIL.getMsg());
List<ResSupplierWhiteListVo> resSupplierWhiteListVos = SupplierWhiteListConverter.toVos(supplierWhiteLists, specialCaseMap);
    PaginationUtil.pageConvert(queryPage, resultPage, resSupplierWhiteListVos);
    return resultPage;
}

// Mapper.java定義
List<SupplierWhiteList> selectByConditionsByPage(@Param("queryPage") Page<SupplierWhiteList> queryPage, @Param("reqSupplierWhitelistQueryVO") ReqSupplierWhiteListQueryVO req);

<select id="selectByConditionsByPage"
       resultType="com.yonghui.yh.rme.srm.suppliercenter.dao.entity.SupplierWhiteList">
   select
   <include refid="Base_Column_List"/>
   from supplier_white_list
   <where>is_delete = 0
       <if test="reqSupplierWhitelistQueryVO.supplierCodes != null and reqSupplierWhitelistQueryVO.supplierCodes.size > 0">
           and supplier_code in
           <foreach collection="reqSupplierWhitelistQueryVO.supplierCodes" separator="," open="(" close=")"
                    item="item">
               #{item}
           </foreach>
       </if>
       <if test="reqSupplierWhitelistQueryVO.purchaseOrgCodes != null and reqSupplierWhitelistQueryVO.purchaseOrgCodes.size > 0">
           and purchase_org_code in
           <foreach collection="reqSupplierWhitelistQueryVO.purchaseOrgCodes" separator="," open="(" close=")"
                    item="item">
               #{item}
           </foreach>
       </if>
       <if test="reqSupplierWhitelistQueryVO.brandLevel != null">
           and brand_level = #{reqSupplierWhitelistQueryVO.brandLevel}
       </if>
       <if test="reqSupplierWhitelistQueryVO.supplierAttributeCode != null and reqSupplierWhitelistQueryVO.supplierAttributeCode!=''">
           and supplier_attribute_code = #{reqSupplierWhitelistQueryVO.supplierAttributeCode}
       </if>
       <if test="reqSupplierWhitelistQueryVO.supplierAttributeName != null and reqSupplierWhitelistQueryVO.supplierAttributeName!=''">
           and supplier_attribute_name = #{reqSupplierWhitelistQueryVO.supplierAttributeName}
       </if>
       <if test="reqSupplierWhitelistQueryVO.updateStartTime != null">
           and updated_time &gt;= #{reqSupplierWhitelistQueryVO.updateStartTime}
       </if>
       <if test="reqSupplierWhitelistQueryVO.updatedEndTime != null">
           and updated_time &lt; #{reqSupplierWhitelistQueryVO.updatedEndTime}
       </if>
   </where>
</select>

到了這里,關(guān)于批量插入、更新mapper寫(xiě)法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Mybatis批量插入/更新性能優(yōu)化思路

    ????????最近在做數(shù)據(jù)寫(xiě)入服務(wù)的性能優(yōu)化,主要是基于Mybatis-Plus實(shí)現(xiàn)一套批量寫(xiě)數(shù)據(jù)的服務(wù),不過(guò)該服務(wù)是支持整個(gè)平臺(tái)所有需要持久化的業(yè)務(wù)實(shí)體。所以這種服務(wù)不僅僅有insert操作還有update的操作。根據(jù)以往的MySQL數(shù)據(jù)庫(kù)寫(xiě)入經(jīng)驗(yàn),主要總結(jié)了兩套批量插入、批量插入

    2024年04月25日
    瀏覽(23)
  • 使用saveOrUpdateBatch實(shí)現(xiàn)批量插入更新數(shù)據(jù)

    saveOrUpdateBatch 是 Hibernate 中的一個(gè)方法,可以用來(lái)批量插入或更新數(shù)據(jù)。這個(gè)方法的參數(shù)是一個(gè) List,里面可以存儲(chǔ)多個(gè)實(shí)體對(duì)象。當(dāng) Hibernate 執(zhí)行這個(gè)方法時(shí),會(huì)檢查每個(gè)實(shí)體對(duì)象是否存在主鍵,如果存在主鍵就執(zhí)行 update 操作,否則執(zhí)行 insert 操作。 使用 saveOrUpdateBatch 的代

    2024年02月11日
    瀏覽(26)
  • 18. ElasticSearch系列之批量插入與更新

    本文介紹工作中Python版常用的高效ES批量插入、更新數(shù)據(jù)方式 1. 批量插入 2.批量更新 批量更新只需要改動(dòng)action的以下內(nèi)容即可 歡迎關(guān)注公眾號(hào)算法小生或沈健的技術(shù)博客

    2024年02月11日
    瀏覽(15)
  • 批量插入或更新數(shù)據(jù)(MyBatis-plus框架)

    批量插入或更新數(shù)據(jù)(MyBatis-plus框架)

    目錄 1.場(chǎng)景說(shuō)明 2.DUPLICATE?和REPLACE比較 3.批量插入或者更新(兩種方式) 方式一:mybatis-plus的saveOrUpdateBatch方法 問(wèn)題:如果操作類集成了基礎(chǔ)類,比如封裝了BaseEntity去集成,那么這樣使用會(huì)出問(wèn)題 方式二:on duplicate key (推薦) 4.注意 5.常見(jiàn)問(wèn)題? 插入數(shù)據(jù)時(shí),我們經(jīng)常會(huì)遇到這

    2024年02月04日
    瀏覽(24)
  • Mysql 實(shí)現(xiàn)批量插入對(duì)已存在數(shù)據(jù)忽略或更新

    Mysql 實(shí)現(xiàn)批量插入對(duì)已存在數(shù)據(jù)忽略或更新

    對(duì)已存在的數(shù)據(jù)進(jìn)行 忽略/更新 ,需要唯一索引/主鍵。 唯一索引可為多個(gè)字段的聯(lián)合索引,比如根據(jù)我提供的sql中,我需要``name + age`不重復(fù),則可把這2個(gè)字段聯(lián)合創(chuàng)建為唯一索引 創(chuàng)建聯(lián)合唯一索引的sql 批量插入對(duì)已存在數(shù)據(jù)忽略 批量插入對(duì)已存在數(shù)據(jù)更新 筆者這里只舉

    2024年02月15日
    瀏覽(29)
  • springboot使用aop排除某些方法,更新從另外一張表,從另外一張表批量插入

    在Spring Boot中使用AOP時(shí),如果想要排除某些方法不被切面所影響,可以通過(guò)使用切面表達(dá)式中的!within來(lái)實(shí)現(xiàn)。以下是一個(gè)示例: 在上面的示例中,@Before注解用于定義切面的beforeAdvice方法。execution(* com.example.service. . (…))表示切入所有com.example.service包下的方法。而!wit

    2024年02月13日
    瀏覽(28)
  • Spring Boot Elasticsearch7.6.2實(shí)現(xiàn)創(chuàng)建索引、刪除索引、判斷索引是否存在、獲取/添加/刪除/更新索引別名、單條/批量插入、單條/批量更新、刪除數(shù)據(jù)、遞歸統(tǒng)計(jì)ES聚合的數(shù)據(jù)

    注意:我的版本是elasticsearch7.6.2、spring-boot-starter-data-elasticsearch-2.5.6 引入依賴 有時(shí)候你可能需要查詢大批量的數(shù)據(jù),建議加上下面配置文件

    2024年02月13日
    瀏覽(101)
  • Mybatis mapper.xml 判斷條件寫(xiě)法注意

    1.判斷String是否為空 if?test=\\\"stringParam != null and?stringParam?!= \\\'\\\'\\\"/if 2.判斷Integer是否大于0 判斷等于? when test=\\\"item.mark == 1\\\"\\\" 3.判斷List是否不為空 5.判斷字符串是否等于特定字符(比如此處的user)

    2024年02月16日
    瀏覽(32)
  • Mybatis-Plus 自定義mapper批量新增修改函數(shù)

    version MybatisPlusConfig CustomizedSqlInjector InsertBatchMethod UpdateBatchMethod RootMapper 使用方式 mapper接口實(shí)現(xiàn)自定義的RootMapper,即可調(diào)用批量新增修改函數(shù)

    2024年02月12日
    瀏覽(32)
  • 問(wèn)題解決:使用Mybatis Plus的Mapper插入達(dá)夢(mèng)數(shù)據(jù)庫(kù)報(bào)“數(shù)據(jù)溢出”錯(cuò)誤

    問(wèn)題解決:使用Mybatis Plus的Mapper插入達(dá)夢(mèng)數(shù)據(jù)庫(kù)報(bào)“數(shù)據(jù)溢出”錯(cuò)誤

    使用Mybatis Plus的Mapper插入達(dá)夢(mèng)數(shù)據(jù)庫(kù)報(bào)“數(shù)據(jù)溢出”錯(cuò)誤 問(wèn)題描述 在進(jìn)行批量插入中,拋出異常為數(shù)據(jù)溢出 插入方法:this.baseMapper.insertBatchSomeColumn() 拋出異常:數(shù)據(jù)溢出 對(duì)失敗的數(shù)據(jù)進(jìn)行循環(huán),嘗試使用單個(gè)插入的方法,同樣拋出異常為數(shù)據(jù)溢出 插入方法:this.baseMapper

    2024年02月07日
    瀏覽(284)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包