MyBatis批量修改操作


1.需求

  后台管理頁面,查詢頻道列表,需要批量修改頻道的狀態,批量上線和下線

2.MyBatis配置

這是mysql的配置,注意需要加上&allowMultiQueries=true配置

jdbc_url=jdbc:mysql://localhost:3306/go?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true

<update id="batchUpdate"  parameterType="java.util.List">
         <foreach collection="list" item="item" index="index" open="" close="" separator=";">
               update channels
               <set>
                 state=${item.state}
               </set>
               where id = ${item.id}
        </foreach>
 </update>

3. oracle和mysql的配置不一樣,這里也記一下

<update id="batchUpdate"  parameterType="java.util.List">
         <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";">
               update channels
               <set>
                 state=${item.state}
               </set>
               where id = ${item.id}
        </foreach>
 </update>

 Mysql的配置在實際運用中成功了,Oracle的沒有試過

 參考http://my.oschina.net/jsonavaj/blog/265112


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM