T S*_*res 4 java syntax list insert mybatis
我试图在数据库中插入一个列表,但我有一些错误:org.springframework.jdbc.BadSqlGrammarException:SqlSession操作; 糟糕的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>
Run Code Online (Sandbox Code Playgroud)
我的道歉方法:
SqlSessionTemplate().insert(MAPPER+".insertListMyObject", parameterList);
Run Code Online (Sandbox Code Playgroud)
parameterList的位置是:
List<MyObjects>.
Run Code Online (Sandbox Code Playgroud)
有人知道这个错误是什么?或者,如果确实存在多个插入操作的更好方法.
非常感谢!
通过使用以下查询,您可以使用 Mybatis 和 Oracle 一次插入多条记录。
<insert id="insertListMyObject" parameterType="map" >
BEGIN
insert into table_name values (11,11);
insert into table_name2 values (11,112);
END;
</insert>
Run Code Online (Sandbox Code Playgroud)
这就是我为甲骨文所做的事情,它有效。请注意,parameterType=map
地图不一定是地图,它可以是根据您的需要的任何内容。
归档时间: |
|
查看次数: |
23345 次 |
最近记录: |