我试图在数据库中插入一个列表,但是出现了一些错误:org.springframework.jdbc.BadSqlGrammarException:SqlSession operation;错误的SQL语法[];嵌套的异常是java.sql.SQLException:ORA-00913:值太多(...)。

我使用的代码:

<insert id="insertListMyObject" parameterType="java.util.List" >
INSERT INTO my_table
   (ID_ITEM,
    ATT1,
    ATT2)
    VALUES
   <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
    #{item.idItem, jdbcType=BIGINT},
    #{item.att1, jdbcType=INTEGER},
    #{item.att2, jdbcType=STRING}
       </foreach>
</insert>

我的方法是:
SqlSessionTemplate().insert(MAPPER+".insertListMyObject", parameterList);

其中parameterList是:
List<MyObjects>.

有人对这个错误有什么头绪吗?或者,如果存在更好的方法来执行多次插入操作。

非常感谢!

最佳答案

如下设置分隔符

separator="),("

07-25 22:51