mybatis 批量插入 Column count doesn‘t match value count at row 1


mybatis 批量插入问题

错误的写法:

INSERT INTO t_csm_customer_product(id, customer_code, product_code) values

    #{cstProduct.id},
    #{cstProduct.customerCode},
    #{cstProduct.productCode}

异常信息 Error updating database...Cause: java.sql.SQLException: Column count doesn't match value count at row 1 

打印sql后发现:

INSERT INTO table(id, name, value) values ( ?,?,?,?,?,?) 

 整个括号括起来了 

我们想要的sql:

INSERT INTO table(id, name, value) values ( ?,?,?),(?,?,?)  

调整xml为:

INSERT INTO t_csm_customer_product(id, customer_code, product_code) values

    (#{cstProduct.id},
    #{cstProduct.customerCode},
    #{cstProduct.productCode})

重点 foreach 内参数 缺少 ()