记录一次在Mybatis中批量添加的操作
1、sql底层支撑!
sql底层添加可以向这样出现,所以MyBatis中只要拼成这样既能实现批量
insert into orderitem(order_id, product_id, buynum) values (?,?,?) , (?,?,?) , (?,?,?)
2、我的实现
void addOrderItem(List<Orderitem> orderItems);
<!--添加订单项-->
<insert id="addOrderItem" parameterType="com.wnx.mall.tiny.mbg.model.Orderitem">
insert into orderitem(order_id, product_id, buynum) values
<foreach collection="list" separator="," item="orderItem">
(#{orderItem.orderId},#{orderItem.productId},#{orderItem.buynum})
</foreach>
</insert>
|