<update id="updateBatch" parameterType="java.util.List"> UPDATE DB.INVOICE <!-- 修改的表明需要改 --> <trim prefix="SET" suffixOverrides=","> <trim prefix="INVOICE_NO = CASE" suffix="END,"> <!-- prefix INVOICE_NO 需要修改 --> <foreach collection="list" item="item" index="index"> <if test="item.invoiceNo!=null"><!-- test中 invoiceNo 需要修改 --> <!-- INVOICE_ID SERIALNO 是已知条件需要修改 ,THEN后面是即将要set的值 --> WHEN INVOICE_ID=#{item.invoiceId} AND SERIALNO=#{item.serialno} THEN #{item.invoiceNo} </if> </foreach> </trim> <trim prefix="INVOICE_CODE = CASE" suffix="END," > <foreach collection="list" item="item" index="index"> <if test="item.invoiceCode!=null"> WHEN INVOICE_ID=#{item.invoiceId} AND SERIALNO=#{item.serialno} THEN #{item.invoiceCode} </if> </foreach> </trim> </trim> WHERE <foreach collection="list" item="item" index="index" open=" (" separator= ") OR (" close=")"> INVOICE_ID=#{item.invoiceId} AND SERIALNO=#{item.serialno} </foreach> </update>
注意建议300-500条以内,避免sql过长