Mybatis foreach 中批量更新的用法

 
    update <include refid="***" />
    set name= '1'
    where sid in
    
      #{item,jdbcType=VARCHAR}
    foreach>
  update >

其中当dao层接口使用@Param("***")绑定参数
collection属性为绑定的参数名

当未使用@Param("***")绑定参数
collection属性为list 或 array
item为别名

批量插入
dao层接口

public interface FundMapper {
	
		int insertForeach(List<Fund> list);
	}
<insert id="insertForeach" parameterType="java.util.List" useGeneratedKeys="false">
    			insert into fund
    			( id,fund_name,fund_code,date_x,data_y,create_by,create_date,update_by,update_date,remarks,del_flag)
    			values
    			<foreach collection="list" item="item" index="index" separator=",">
    				(
    					#{item.id},
    					#{item.fundName},
    					#{item.fundCode},
    					#{item.dateX},
    					#{item.dataY},
    					#{item.createBy},
    					#{item.createDate},
    					#{item.updateBy},
    					#{item.updateDate},
    					#{item.remarks},
    					#{item.delFlag}
    				)
    		     foreach>		
    insert>    


<select id="batchInsert" parameterType="java.util.List">  
        insert into apk_statistic_raw  
        (uuid,apk_id,event_id,supply_id,channel_id,file_upload_record_id,product_name,content,time,numbers,status,creator,create_time,other  
        )values  
        <foreach collection="list" item="item" index="index"  
            separator=",">  
            (#{item.uuid,jdbcType=CHAR},#{item.apkId,jdbcType=CHAR},#{item.eventId,jdbcType=CHAR},#{item.supplyId,jdbcType=INTEGER},#{item.channelId,jdbcType=INTEGER}  
            ,#{item.fileUploadRecordId,jdbcType=CHAR},#{item.productName,jdbcType=VARCHAR},#{item.content,jdbcType=VARCHAR},#{item.time,jdbcType=BIGINT},  
            #{item.numbers,jdbcType=INTEGER},#{item.status,jdbcType=INTEGER},#{item.creator,jdbcType=VARCHAR},#{item.createTime,jdbcType=BIGINT},#{item.other,jdbcType=VARCHAR}  
            )  
        foreach>  
    select>  

添加链接描述
https://blog.csdn.net/wsjzzcbq/article/details/81779588

你可能感兴趣的:(JAVA,EE企业级实战)