zoukankan      html  css  js  c++  java
  • MyBatis批量修改

    批量修改-xml代码

    mybatis批量查询,批量新增就不聊了,今天看看批量修改。
    直接上代码吧
    xml文件中代码如下:

    
    <update id="updateBatchById" parameterType="java.util.List">
        update
            employee
        set
            userName =
            <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
                when #{item.id} then #{item.userName}
            </foreach>
        , age =
            <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
                when #{item.id} then #{item.age}
            </foreach>
        where
            ID
        in
            <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
                #{item.id}
            </foreach>
    </update>
    
    

    运行出来的代码如下

        update
            employee
        set 
            userName =
        case ID
            when ? then ?
        case ID
            when ? then ?
        end
            , age =
        case ID
            when ? then ?
        case ID
            when ? then ?
        end
        where
            ID
        in
            (?,?)
    

    mapper层代码

    
        /**
         *批量修改员工信息
         * @param employees
         */
        public boolean updateBatchById(List<Employee> employees);
    
    
  • 相关阅读:
    POJ 2411 Mondriaan's Dream -- 状压DP
    codeforces 792A-D
    codeforces 796A-D
    Acdream1201 SuSu's Power
    HDU 2818 Building Block
    C# NetStream
    基于Duff's Device的C简易无栈协程实现
    CentOS 多版本 GCC 共存
    2017杭电多校第一场
    2019杭电多校第十场
  • 原文地址:https://www.cnblogs.com/orangebooks/p/11799080.html
Copyright © 2011-2022 走看看