mybatis 进行批量修改操作

批量修改时候传入多个数值不想在service层 进行循环修改,
想在写sql语句的时候进行批量修改
传入的有全部的id和需要修改的数据。怎么写sql语句。。。
只会删除的时候传入id的语句,,现在多个参数不会写了。。

    <update id="batchUpdate" parameterType="java.util.List">  
                        UPDATE STUDENT
                        <set> 
                                <if test="bannerName != null">
                                        t.banner_name = #{bannerName},
                                </if>
                                <if test="bannerUrl != null">
                                        t.banner_url = #{bannerUrl},
                                </if>
                        </set>                                  
                        WHERE id IN  
                    <foreach collection="list" item="item" index="index" open="(" separator="," close=")" >  
                            #{item}  
                    </foreach>  
</update>  

update tablename set xxx = xxx where id in (xxx,xxx,xxx)

或者
        <update id="batchUpdate" parameterType="java.util.List">  
    UPDATE STUDENT SET name = "250" WHERE id IN  
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")" >  
        #{item}  
    </foreach>  
</update>  

set不是固定值,是前台传过来的

mybatis自动生成的update就可以动态set

使用动态sql

update student


id=#{id} ,


last_name=#{lastName} ,


email=#{email} ,


<update id="Update" >  
    UPDATE STUDENT    
 <trim prefix="set " suffixOverrides=",">
             <if test="lastName!=null and lastName!=''">
                 last_name=#{lastName} ,
             </if>
             <if test="email!=null and email.trim()!=''">
                 email=#{email} ,
             </if>
         </trim>
                where id in
        <foreach collection="list" item="item" index="index" open="(" separator="," close=")" >  
        #{item}  
    </foreach> 
    </update>

给你个模板,自己换一下字段就好了,传入的参数是实体类

 <update id="delete">
        DELETE FROM wsd_count
        <where>
            <if test="id != null and id != ''">
                AND id = #{id}
            </if>
            <if test="uid != null and uid != ''">
                AND uid = #{uid}
            </if>
            <if test="line != null and line != ''">
                AND line LIKE 
                    <if test="dbName == 'oracle'">'%'||#{line}||'%'</if>
                    <if test="dbName == 'mssql'">#{line}+'%'</if>
                    <if test="dbName == 'mysql'">concat('%',#{line},'%')</if>
            </if>
            <if test="num != null and num != ''">
                AND num = #{num}
            </if>
            <if test="result != null and result != ''">
                AND result = #{result}
            </if>
            <if test="data != null and data != '' and countReserve5 != null and countReserve5 != ''">
                AND data BETWEEN #{data} AND #{countReserve5}
            </if>
        </where>
    </update>

mybatis的批量操作executor