欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

批量操作list对象

程序员文章站 2022-07-04 17:05:10
...
<insert id="insertForeach" parameterType="java.util.List">
         insert into mb_member_devinfo (id, member_id, name, 
         phone, org_id, org_name, 
         stage, state, sort, 
         createtime, tenant_code)
     	values 
      <foreach collection="list" item="item" index="index" separator="," >  
        (#{item.id,jdbcType=VARCHAR}, #{item.memberId,jdbcType=VARCHAR}, #	

{item.name,jdbcType=VARCHAR}, 
          #{item.phone,jdbcType=VARCHAR}, #{item.orgId,jdbcType=VARCHAR}, #	

{item.orgName,jdbcType=VARCHAR}, 
          #{item.stage,jdbcType=VARCHAR},#{item.state,jdbcType=VARCHAR}, #	

{item.sort,jdbcType=VARCHAR}, 
          #{item.createtime,jdbcType=BIGINT}, #	

{item.tenantCode,jdbcType=VARCHAR})
      </foreach>
</insert>

 

<update id="updateForeach" parameterType="java.util.List">
        update mb_member_login
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="password = case" suffix="end,">
                 <foreach collection="list" item="item" index="index">
                         when member_id=#{item.memberId} then #		

			{item.password}
                 </foreach>
            </trim>
        </trim>
        where member_id in
        <foreach collection="list" index="index" item="item" 
         separator="," 	open="(" close=")">
            #{item.memberId,jdbcType=BIGINT} 
        </foreach>
            and  state='1'
</update>

 

相关标签: mybatis