mysql批量更新

map


    /**
     * 根据员工code 批量更新 userid
     *
     * @param resultMap key为nsCode, value 为userId
     */
    void updateBatchUserIdByEmpCode(@Param("map") Map<String, Integer> resultMap);
<update id="updateBatchUserIdByEmpCode" parameterType="java.util.Map">
        UPDATE sys_employee
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="user_id =case" suffix="end,">
                <foreach collection="map" index="key" item="value">
                    WHEN ns_code = #{key} THEN #{value}
                </foreach>
            </trim>
        </trim>
        WHERE ns_code IN
        <foreach collection="map" index="key" item="value" separator="," open="(" close=")">
            #{key}
        </foreach>
    </update>

list:

    /**
     * 批量更新员工信息 (北森) 目前只更新 学历 跟 性别 用于补偿
     *
     * @param employeeInfos 北森字段信息
     */
    void updateBatchEmpInfo(@Param("list") List<EmployeeInfo> employeeInfos);

<update id="updateBatchEmpInfo" parameterType="java.util.List">
        UPDATE sys_employee
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="education_level =case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    WHEN user_id = #{item.userID} THEN #{item.educationLevel}
                </foreach>
            </trim>
            <trim prefix="gender =case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    WHEN user_id = #{item.userID} THEN #{item.gender}
                </foreach>
            </trim>
        </trim>
        WHERE user_id IN
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item.userID}
        </foreach>
    </update>

你可能感兴趣的:(mysql,数据库)