您的位置:首页 > 其它

mybatis数据批量更新

2014-07-03 10:45 197 查看
原sql语句:
update zyjd set peopleId=case
when id=1 then 10,
when id=2 then 11 end,
roadgridid =case
when id=1 then 101,
when id=2 then 102 end,
…………
where id=1 or id=2
sql意思:当id=1的情况下peopleId =10,roadgridid =101,当id=2的情况下peopleId =11,roadgridid =102,等等
mybatis配置文:
<update id="batchUpdate" parameterType="list">
update zyjd
<trim prefix="set" suffixOverrides=",">
<trim prefix="peopleId =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.peopleId!=null">
when id=#{i.id} then #{i.peopleId}
</if>
</foreach>
</trim>
<trim prefix=" roadgridid =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.roadgridid!=null">
when id=#{i.id} then #{i.roadgridid}
</if>
</foreach>
</trim>

<trim prefix="type =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.type!=null">
when id=#{i.id} then #{i.type}
</if>
</foreach>
</trim>
<trim prefix="unitsid =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.unitsid!=null">
when id=#{i.id} then #{i.unitsid}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index" >
id=#{i.id}
</foreach>
</update>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据更新 mybatis