方法一:
<insert id="batchInsert" parameterType="java.util.List">
INSERT ALL
<foreach collection="list" item="item" index="index">
INTO TEST
(
USERNAME,
PASSWORD
) VALUES
(
#{item.userName, jdbcType=NUMERIC},
#{item.password, jdbcType=VARCHAR}
)
</foreach>
SELECT 1 FROM DUAL
</insert>
方法二:<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO TEST
(
USERNAME,
PASSWORD
)
<foreach collection="list" item="item" index="index" open="(" separator="union all" close=")">
SELECT
#{item.userName, jdbcType=NUMERIC},
#{item.password, jdbcType=VARCHAR}
FROM DUAL
</foreach>
</insert>