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);
    
    
  • 相关阅读:
    R-FCN、SSD、YOLO2、faster-rcnn和labelImg实验笔记
    yolov3的anchor机制与损失函数详解
    CV资料推荐
    测试用例设计方法总结
    测试需求分析
    bug生命周期
    linux命令一
    linux 命令二
    linux 命令三
    mysql数据库和禅道安装
  • 原文地址:https://www.cnblogs.com/orangebooks/p/11799080.html
Copyright © 2011-2022 走看看