话不多说,直接上代码。能看懂格式即可
1、第一种,以insert into tb_name values(~~~),values(~~~),values(~~~),values(~~~),values(~~~),values(~~~)(以逗号间隔)
<insert id="batchInsertProductCategory" parameterType="java.util.List">
insert into tb_product_category
(product_category_id,product_category_name,weight,create_time,shop_id)
values
<foreach collection="list" item="productCategory" separator=",">
(#{productCategory.productCategoryId},#{productCategory.productCategoryName},
#{productCategory.weight},#{productCategory.createTime},#{productCategory.shopId})
</foreach>
</insert>
第二种,执行多次insert,insert into tb_name ~~~;insert into tb_name~~~;(以分号间隔)
<insert id="batchInsertProductCategory" parameterType="java.util.List"> <foreach collection="list" item="productCategory" separator=";"> insert into tb_product_category (product_category_id,product_category_name,weight,create_time,shop_id) values (#{productCategory.productCategoryId},#{productCategory.productCategoryName}, #{productCategory.weight},#{productCategory.createTime},#{productCategory.shopId}) </foreach> </insert>
推荐以第一种方式