DAO接口: int insertAllSelective(List<PrivilegeCouponPackageRecord> list);
Mapper:
<insert id="insertAllSelective" parameterType="java.util.List" useGeneratedKeys="false"> insert into msr_privilege_coupon_package_record (member_id, member_phone, order_id, batch_sign, package_id, rp_code,expected_time) VALUES <foreach collection="list" item="item" index="index" separator=","> ( #{item.memberId}, #{item.memberPhone}, #{item.orderId}, #{item.batchSign}, #{item.packageId}, #{item.rpCode}, #{item.expectedTime} ) </foreach> </insert>
service调用:
@Transactional(rollbackFor = {Exception.class}) public boolean insertAllCouponInfos(List<PrivilegeCouponPackageRecord> couponInfos) throws Exception { int insertResult = privilegeCouponPackageRecordMapper.insertAllSelective(couponInfos); if(insertResult != couponInfos.size()) { throw new Exception("[GetCouponService.insertAllCouponInfos]券基础信息入库失败,memberId:" + couponInfos.get(0).getMemberId() +",orderId:" + couponInfos.get(0).getOrderId()); } return true; }