mybatis批量修改数据,批量插入数据,批量删除数据,多表查询

本文介绍使用MyBatis进行批量修改、插入、删除数据的方法,并演示了多表查询的实现方式。详细展示了如何通过XML映射文件定义批量操作的SQL语句,以及如何利用foreach标签进行循环遍历集合数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

mybatis批量修改数据,批量插入数据,批量删除数据,多表查询

连接地址
1.批量修改数据

 //批量修改产品信息数据,参数是map集合对象
 Integer batchUpateProductInfo(Map<String,Object> map);

<!--批量修改产品信息数据-->
    <update id="batchUpateProductInfo" parameterType="java.util.Map">
        update ${tableName}
        <set>
            status = #{status,jdbcType=INTEGER},
            last_operator = #{lastOperator,jdbcType=VARCHAR},
            last_operator_id = #{lastOperatorId,jdbcType=INTEGER},
            display_status = #{displayStatus,jdbcType=INTEGER},
            last_operator_time =#{lastOperatorTime,jdbcType=TIMESTAMP},
            update_time = #{updateTime,jdbcType=TIMESTAMP}
        </set>
        where  ${target} IN
        <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </update>

2.批量新增数据

 /**
     * 批量新增企业联系人
     * @param uacEnterpiseContactList
     * @return
     */
    Integer batchAddEnterpiseContact(List<UacEnterpiseContact> enterpiseContactList);

<!-- 批量插入企业联系人信息 -->
    <insert id="batchAddEnterpiseContact" parameterType="java.util.List">
        insert into enterpise_contact
        (version, 
        name,
        enterpise_id, 
        dept, 
        position,
        email, 
        gender, 
        phone,
        hobby, 
        address,
        remark, 
        creator,
        creator_id,
        created_time, 
        last_operator,
        last_operator_id,
        last_operator_time,
        update_time,
        status)
        values
        <foreach collection="list" item="t" index="index" separator=",">
            (
                #{t.version,jdbcType=BIGINT},
                #{t.name,jdbcType=VARCHAR},
                #{t.enterpiseId,jdbcType=BIGINT},
                #{t.dept,jdbcType=VARCHAR},
                #{t.position,jdbcType=VARCHAR},
                #{t.email,jdbcType=VARCHAR},
                #{t.gender,jdbcType=INTEGER},
                #{t.phone,jdbcType=VARCHAR},
                #{t.hobby,jdbcType=VARCHAR},
                #{t.address,jdbcType=VARCHAR},
                #{t.remark,jdbcType=VARCHAR},
                #{t.creator,jdbcType=VARCHAR},
                #{t.creatorId,jdbcType=BIGINT},
                #{t.createdTime,jdbcType=TIMESTAMP},
                #{t.lastOperator,jdbcType=VARCHAR},
                #{t.lastOperatorId,jdbcType=BIGINT},
                #{t.lastOperatorTime,jdbcType=TIMESTAMP},
                #{t.updateTime,jdbcType=TIMESTAMP},
                #{t.status,jdbcType=INTEGER}
            )
        </foreach>
    </insert>

3.批量删除数据

 /**
     * 批量删除企业联系人
     * @param map
     * @return
     */
    Integer batchDeleteEnterpiseContact(Map<String, Object> map);
  <!--批量删除企业联系人-->
    <delete id="batchDeleteEnterpiseContact" parameterType="java.util.Map">
        delete from enterpise_contact
        where  ${target} IN
        <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </delete>

4.多表查询

 <resultMap id="relationFlowMap" type="com.focus.service.vo.FlowTemRelVo">
        <id column="flowId" jdbcType="BIGINT" property="flowId"></id>
        <result column="flowName" jdbcType="VARCHAR" property="flowName"></result>
        <collection property="sccFileRelTemVoList" ofType="com.focus.service.vo.FileRelTemVo">
            <id column="id" jdbcType="BIGINT" property="id"></id>
            <result column="fileName" jdbcType="VARCHAR" property="fileName"></result>
        </collection>
    </resultMap>


   <select id="getRelationFlowByNameAndEntId" resultMap="relationFlowMap">
       select
       t1.id flowId,
       t1.name flowName,
       t3.id,
       t3.name fileName
       from
       scc_flow t1
       left join
       scc_flow_file t2
       on
       t1.id = t2.flow_id
       left join
       scc_file t3
       on t2.file_id = t3.id
       <where>
           t1.status = 0
           and t1.enterpise_id = #{enterpiseId}
           <if test="name != null and name != ''">
               and (t1.name like concat('%',#{name},'%') escape '/' or t3.name like concat('%',#{name},'%') escape '/')
           </if>
       </where>
       order by t1.name
   </select>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值