myBatis批量增删改和批量增OR删


<update id="batchEdit" parameterType="java.util.List">
    update  CUSTOMER
    <trim prefix="set" suffixOverrides=",">
          <trim prefix="USER_ID =case" suffix="end,">
              <foreach collection="list" item="item" index="index">
                  <if test="item.USER_ID != null">
                   when CUSTOMER_ID=#{item.CUSTOMER_ID} then #{item.USER_ID}
                  if>
              foreach>
           trim>
          <trim prefix="NAME =case" suffix="end,">
              <foreach collection="list" item="item" index="index">
                  <if test="item.NAME != null">
                   when CUSTOMER_ID=#{item.CUSTOMER_ID} then #{item.NAME}
                  if>
              foreach>
          trim>
      trim>
      where
        <foreach collection="list" separator="or" item="item" index="index" >
            CUSTOMER_ID=#{item.CUSTOMER_ID}
        foreach>
update>

  <insert id="saveByBatch" parameterType="java.util.List">
      insert into PRO_ORDER(
    ORDER_NO,   
    USER_ID,    
    APPUSER_ID, 
    CONSUME_TOTAL,  
    NUM,    
    CODE,   
    CONSIGNEE,  
    PHONE,  
    ADDRESS,    
    STATUS, 
    CREATE_DATE,    
    ALL_ORDER_ID,   
    PRO_ORDER_ID
) values
      <foreach collection="list" item="item" index="index" separator=",">
          (#{item.ORDER_NO},    
    #{item.USER_ID},    
    #{item.APPUSER_ID}, 
    #{item.CONSUME_TOTAL},  
    #{item.NUM},    
    #{item.CODE},   
    #{item.CONSIGNEE},  
    #{item.PHONE},  
    #{item.ADDRESS},    
    #{item.STATUS}, 
    #{item.CREATE_DATE},    
    #{item.ALL_ORDER_ID},   
    #{item.PRO_ORDER_ID}
    )
      foreach>
  insert>

<delete id="deleteAll" parameterType="String">
    delete from PRO_ORDER
    where 
    PRO_ORDER_ID in
<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
         #{item}
foreach>
delete>
    
  <insert id="SaveOrUpdate" parameterType="java.util.List">
      insert into CART_PRO_SPEC(
    CART_PRO_ID,    
    PRO_SPEC2_ID,   
    NUM,    
    CART_PRO_SPEC_ID
) values 
      <foreach collection="list" item="item" index="index" separator=",">
          (#{item.CART_PRO_ID},    
       #{item.PRO_SPEC2_ID},    
        #{item.NUM}, 
        #{item.CART_PRO_SPEC_ID}
       )
      foreach>
      ON DUPLICATE KEY UPDATE
        CART_PRO_ID =CASE CART_PRO_SPEC_ID
        <foreach collection="list" item="item" index="index">
        WHEN #{item.CART_PRO_SPEC_ID} THEN #{item.CART_PRO_ID}
    foreach>
    END,
        PRO_SPEC2_ID =CASE CART_PRO_SPEC_ID
        <foreach collection="list" item="item" index="index">
        WHEN #{item.CART_PRO_SPEC_ID} THEN #{item.PRO_SPEC2_ID}
    foreach>
    END,
        NUM =CASE CART_PRO_SPEC_ID
        <foreach collection="list" item="item" index="index">
        WHEN #{item.CART_PRO_SPEC_ID} THEN #{item.NUM}
    foreach>
    END
  insert>

你可能感兴趣的:(java,myBatis)