SQL insert 批量插入的正确写法

2019-03-29  本文已影响0人  南岩飞雪

问题

 <insert id="bathcInsertOrUpdateXXX">
       <foreach collection="list" item="item" separator=";">
           INSERT INTO xxx(corp_id,user_id,xxx)
           VALUES
           (#{item.corpId}, #{item.userId}, #{item.xxx})
           ON DUPLICATE KEY UPDATE
           xxx = VALUES(xxx)
       </foreach>
   </insert>
TddlNestableRuntimeException### Error updating database.  Cause: java.sql.SQLException: TddlNestableRuntimeException   
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database.  Cause: java.sql.SQLException: TddlNestableRuntimeException
### The error may involve defaultParameterMap
### The error occurred while setting parameters

解决

 <insert id="bathcInsertOrUpdateXXX">
       INSERT INTO xxx(corp_id,user_id,xxx)
       VALUES
       <foreach collection="list" item="item" separator=";">
           (#{item.corpId}, #{item.userId}, #{item.xxx})
       </foreach>
       ON DUPLICATE KEY UPDATE
       xxx = VALUES(xxx)
</insert>

原因

参考

需要注意的 Mybatis 批量插入

上一篇 下一篇

猜你喜欢

热点阅读