无法使用MyBatis将批处理插入Oracle DB

2022-05-06 00:00:00 spring oracle java ibatis mybatis

尝试使用MyBatis(与Spring集成)批量插入Oracle数据库中的表。

这是映射器接口中方法的定义:

public void savePayments(@Param("payments") List<MassPaymentItem> payments);

这是MyBatis XML映射器代码:

<insert id="savePayments" parameterType="MassPaymentFileItem" useGeneratedKeys="false">
    INSERT INTO mass_payments
        (payment_id, file_id, msisdn, amount, status)
    <foreach collection="payments" item="payment" index="index" separator=" UNION ALL ">
        SELECT SEQ_MASS_PAYMENT.nextval, #{payment.fileId}, #{payment.msisdn}, #{payment.amount}, 0 FROM DUAL
    </foreach>
</insert>

当我执行此操作时,收到MyBatiSystemException,并显示消息"嵌套异常是org.apache.ibati.Builder.BuilderException:不正确的内联参数映射格式。应为:#{p.Name,attr1=val1,attr2=val2}"

出了什么问题?如何修复它?


解决方案

我找到解决方案here

<insert id="savePayments">
   INSERT ALL
   <foreach collection="payments" item="payment">
   INTO
      mass_payments_t (payment_id, file_id, msisdn, amount)
   VALUES
      (seq_mass_payment.nextval, #{payment.fileId, javaType=Integer, jdbcType=NUMERIC}, #{payment.msisdn, javaType=String, jdbcType=VARCHAR}, #{payment.amount, javaType=BigDecimal, jdbcType=NUMERIC})
   </foreach>
   SELECT * FROM dual
</insert>

相关文章