mysql 之 mybatis批量插入数据,批量修改

1,//批量插入数据,传入参数list 
     <insert id="insertInfo">
        insert into tableName
	(
	id....
        )
        values
        <foreach collection="list" item="entity" index="index" separator=",">
            (
	    #{entity.id,jdbcType=VARCHAR}....
            )
        </foreach>
    </insert>


2,//批量修改数据
update table set column='...' where id in (1,2,3)  //这样的sql就可以了。

 //Mybatis中这样写就行 (针对修改相同的数据)
<update id="update" parameterType="java.util.Map" >
    UPDATE tableNamw SET name = #{name} 
    WHERE id IN
    <foreach collection="list" item="entity" index="index" open="(" separator="," close=")">
        #{entity.xxx}
    </foreach>
</update>

    //(针对修改不同的数据)
   <update id="batchUpdate" parameterType="java.util.List">  
        <foreach close="" collection="list" index="index" item="item" open="" separator=";">  
            update tableName 
		set name=#{item.name,jdbcType=VARCHAR},
		    age=#{item.age,jdbcType=INTEGER}  
            	where id=#{item.id,jdbcType=INTEGER}  
        </foreach>  
    </update>








  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值