码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis数据批量更新

时间:2014-07-03 14:40:03      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:mybatis

原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数据批量更新,布布扣,bubuko.com

mybatis数据批量更新

标签:mybatis

原文地址:http://6548877.blog.51cto.com/6538877/1433828

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!