IBatis 批量插入数据

时间:2023-03-10 04:17:08
IBatis 批量插入数据

sql语句

<!--批量插入待收流水-->
<insert id="BatchInsertOrder" parameterClass="ArrayList">
INSERT INTO [Order]
([OrdreNo]
,[ClientId]
,[ClientName]
,[ClientPhone]
,[ClientAddr])
VALUES
<iterate conjunction="," open="" close="">
(#[].OrderId#
,#[].ClientId#
,#[].ClientName#
,#[].ClientPhone#
,#[].ClientAddr#
)
</iterate>
</insert>

调用:

public void BatchInsert(IList<Order> entitys)
{
if (entitys == null || entitys.Count <= 0)
return;

for (var i = 0; i < entitys.Count; i += batchInsertCount)
{
var orderList = entitys.Skip(i).Take(batchInsertCount).ToList();
_sqlMapper.Insert("BatchInsertOrder", orderList);
}
}