文章目录
- 1. 第1种
- 2. 第2种
1. 第1种
<insert id="addList" parameterType="java.util.List" useGeneratedKeys="false"> INSERT ALL <foreach item="item" index="index" collection="list"> INTO T_APPLAUD ( ID, USER_ID, BUSINESS_TYPE, PRODUCT_ID, CREATE_TIME ) VALUES ( #{item.id, jdbcType=NUMERIC}, #{item.userId, jdbcType=VARCHAR}, #{item.businessType, jdbcType=VARCHAR}, #{item.productId, jdbcType=VARCHAR}, #{item.createdTime, jdbcType=NUMERIC} ) </foreach> SELECT 1 FROM DUAL </insert>
2. 第2种
<insert id="addList" parameterType="java.util.List" useGeneratedKeys="false"> INSERT INTO T_APPLAUD ( ID, USER_ID, BUSINESS_TYPE, PRODUCT_ID, CREATE_TIME ) <foreach item="item" index="index" collection="list" separator="union all"> ( SELECT #{item.id}, #{item.userId}, #{item.businessType}, #{item.productId}, #{item.createdTime} FROM DUAL ) </foreach> </insert>
注意:将 useGeneratedKeys设置为"false"