<mapper namespace=" " >
<update id="updateByMobile" parameterType="java.util.List">
update pb_vip_table
set integral=
<foreach collection="list" item="item" index="index"
separator=" " open="CASE mobile" close="end">
when #{item.mobile} then #{item.integral}
</foreach>
where mobile in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.mobile,jdbcType=BIGINT}
</foreach>
</update>
</mapper>
原生sql批量更新语句可以看我的上一篇文章,以便更好理解mybatis批量更新。
最好将原生sql语句与mybatis语句进行对比,这样就很容易理解mybatis的一些属性的含义了。
说明:
id=" "名字自己起,我这里起名为updateByMobile,这个是用于dao接口的方法名
parameterType传递的参数类型,我这里传递的参数是数据列表,所以用java.util.List
pb_vip_table是我要更新的表的表名
integral是我要更新的字段,这里我只更新一个字段,更新多个字段类似,