mybatis的批量操作

mybatis 批量添加

<!--批量新建生产资料详情-->
  <insert id="insertBulk" parameterType="java.util.List" >
    insert into mes_pcba_data_detail (pcba_data_detail_id, detail_name, detail_value,
    delflag, pcba_data_id, create_at,
    create_by, update_at, update_by
    )
    values
    <foreach collection="list" item="pd" separator=",">
    (#{pd.pcbaDataDetailId,jdbcType=INTEGER}, #{pd.detailName,jdbcType=VARCHAR}, #{pd.detailValue,jdbcType=VARCHAR},
    #{pd.delflag,jdbcType=INTEGER}, #{pd.pcbaDataId,jdbcType=INTEGER}, #{pd.createAt,jdbcType=TIMESTAMP},
    #{pd.createBy,jdbcType=VARCHAR}, #{pd.updateAt,jdbcType=TIMESTAMP}, #{pd.updateBy,jdbcType=VARCHAR}
    )
    </foreach>
  </insert>

返回的结果是影响行数,
而批量更新:

<update id="updatePcbaDataDetailBulk" parameterType="java.util.List" >
    <foreach collection="list" item="pd" index="index" separator=";" close="" open="">
    update mes_pcba_data_detail
    set detail_name = #{pd.detailName,jdbcType=VARCHAR},
    detail_value = #{pd.detailValue,jdbcType=VARCHAR},
    delflag = #{pd.delflag,jdbcType=INTEGER},
    pcba_data_id = #{pd.pcbaDataId,jdbcType=INTEGER},
    create_at = #{pd.createAt,jdbcType=TIMESTAMP},
    create_by = #{pd.createBy,jdbcType=VARCHAR},
    update_at = #{pd.updateAt,jdbcType=TIMESTAMP},
    update_by = #{pd.updateBy,jdbcType=VARCHAR}
    where pcba_data_detail_id = #{pd.pcbaDataDetailId,jdbcType=INTEGER}
    </foreach>
  </update>

返回的结果是"1”;

你可能感兴趣的:(mybatis的批量操作)