1.检查语法是否有错
2.在不添加数据库连接参数配置参数下,使用以下批量插入语句可正常执行:
<insert id="insertXXX" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
insert into t_table (column1,column2) values
<foreach collection="list" item="item" index="index" separator="," >
<trim prefix="(" suffix=")" suffixOverrides=",">
#{item.column1},#{item.column2},
</trim>
</foreach>
</insert>
但若采用以下方式,需在数据库连接中加入allowMultiQueries=true!
<insert id="insertXXX" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
<foreach collection="list" item="item" index="index" separator=";" >
insert into base_schedule
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="item.column1!= null">
column1,
</if>
<if test="item.column2!= null">
column2,
</if>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="item.column1!= null">
#{item.column1}
</if>
<if test="item.column2!= null">
#{item.column2},
</if>
</foreach>
</insert>
网友评论