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);
    
    
  • 相关阅读:
    xp下双开3389源码
    批处理加密解密原理
    Durango框架开源
    细说PHP5.3.4变量的引用赋值
    svnversion
    sqlite 的使用
    message日志_默认是一周一个日志,保存4周
    Smartmontool 使用
    NETRA之数据库处理
    mysql 日志转
  • 原文地址:https://www.cnblogs.com/orangebooks/p/11799080.html
Copyright © 2011-2022 走看看