Mybatis batch insert problem
Incorrect wording:
INSERT INTO t_csm_customer_product(id, customer_code, product_code) values
<foreach collection="lists" close=")" open="(" index="i" item="cstProduct" separator=",">
#{cstProduct.id},
#{cstProduct.customerCode},
#{cstProduct.productCode}
</foreach>
Error Messages: Error updating database…Cause: java.sql.SQLException: Column count doesn’t match value count at row 1
Print sql:
INSERT INTO table(id, name, value) values ( ?,?,?,?,?,?)
The whole bracket is enclosed
The SQL we want:
INSERT INTO table(id, name, value) values ( ?,?,?),(?,?,?)
Adjust XML to:
INSERT INTO t_csm_customer_product(id, customer_code, product_code) values
<foreach collection="lists" index="i" item="cstProduct" separator=",">
(#{cstProduct.id},
#{cstProduct.customerCode},
#{cstProduct.productCode})
</foreach>
Missing parameter () in key foreach