mybatis 批量插入

mapper.xml
<insert id="insertSelectiveList" parameterType="java.util.Map" useGeneratedKeys="true" keyProperty="id">
<foreach collection="list" item="item" index="index" separator=";">
  insert into buy_receive_addresses
    <include refid="insertSelectNotNull" />
  values (
  <trim suffixOverrides=",">
    <if test="item.id != null">
      #{item.id,jdbcType=INTEGER},
    </if>
    <if test="item.isDefault != null">
      #{item.isDefault,jdbcType=CHAR},
    </if>
    <if test="item.receivePersonalName != null">
      #{item.receivePersonalName,jdbcType=VARCHAR},
    </if>
    <if test="item.area != null">
      #{item.area,jdbcType=VARCHAR},
    </if>
    <if test="item.address != null">
      #{item.address,jdbcType=VARCHAR},
    </if>
    <if test="item.mobile != null">
      #{item.mobile,jdbcType=VARCHAR},
    </if>
    <if test="item.phone != null">
      #{item.phone,jdbcType=VARCHAR},
    </if>
    <if test="item.email != null">
      #{item.email,jdbcType=VARCHAR},
    </if>
    <if test="item.phoneUserId != null">
      #{item.phoneUserId,jdbcType=INTEGER},
    </if>
  </trim>
  )
  </foreach>
</insert>

<sql id="insertSelectNotNull">
  <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="item.id != null">
      id,
    </if>
    <if test="item.isDefault != null">
      is_default,
    </if>
    <if test="item.receivePersonalName != null">
      receive_personal_name,
    </if>
    <if test="item.area != null">
      area,
    </if>
    <if test="item.address != null">
      address,
    </if>
    <if test="item.mobile != null">
      mobile,
    </if>
    <if test="item.phone != null">
      phone,
    </if>
    <if test="item.email != null">
      email,
    </if>
    <if test="item.phoneUserId != null">
      phone_user_id,
    </if>
  </trim>
</sql>
public int insertBuyReceiveAddressesList(List<?> returnDataList) {
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("list",(List<BuyReceiveAddresses>)returnDataList);
   return buyReceiveAddressesMapperDao.insertSelectiveList(map);
}

int insertSelectiveList(Map map);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值