Mybatis批量更新、批量新增--Oracle
程序员文章站
2022-03-10 18:34:56
...
<update id="updateTopicList" parameterType="java.util.List">
UPDATE MEETING_TOPIC
SET TOPIC_STATE=
<foreach collection="list" item="item" index="index"
separator=" " open="case TOPIC_GUID" close="end">
when #{item.topicGuid} then #{item.topicState}
</foreach>
WHERE TOPIC_GUID IN
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.topicGuid,jdbcType=VARCHAR}
</foreach>
</update>
我这是Oracle,Mysql没有测试。加了红框的地方为需要修改为实际参数的地方。写个博客记录一下。
批量新增
<insert id="saveList" parameterType="java.util.List" >
INSERT INTO MEETING_TOPIC_CHECKINFO
(TCHECK_GUID, TCHECK_TOPIC_GUID, TCHECK_PERSON_GUID,TCHECK_PERSON_NAME,TCHECK_STEP, TCHECK_CHECK_STATE,
TCHECK_CHECK_MSG, TCHECK_CREATE_DATE,TCHECK_CHECK_DATE)
<foreach open="(" collection="list" item="tcInfo" index="index" close=")" separator="UNION ALL">
SELECT
#{tcInfo.tcheckGuid,jdbcType=VARCHAR}, #{tcInfo.tcheckTopicGuid,jdbcType=VARCHAR},
#{tcInfo.tcheckPersonGuid,jdbcType=VARCHAR},#{tcInfo.tcheckPersonName,jdbcType=VARCHAR},
#{tcInfo.tcheckStep,jdbcType=INTEGER}, #{tcInfo.tcheckCheckState,jdbcType=INTEGER},
#{tcInfo.tcheckCheckMsg,jdbcType=VARCHAR}, #{tcInfo.tcheckCreateDate,jdbcType=TIMESTAMP},
#{tcInfo.tcheckCheckDate,jdbcType=TIMESTAMP}
FROM DUAL
</foreach>
</insert>