zoukankan      html  css  js  c++  java
  • mybatis执行批量更新batch update 的方法

    1、数据库连接必须配置:&allowMultiQueries=true

      我的配置如下:jdbc:mysql://10.20.13.16:3306/CALENDAR?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true

    2、批量修改并加判断条件(修改字段可选)

        <!-- 批量更新赛程 -->
        <update id="updateMatchs" parameterType="java.util.List">
            <foreach collection="matchs" item="item" index="index" open="" close="" separator=";">
                update t_match
                <set>
                    <if test="item.title !=null">
                        TITLE = #{item.title,jdbcType=VARCHAR},
                    </if>
                    <if test="item.homeScore !=null">
                        HOME_SCORE = #{item.homeScore,jdbcType=INTEGER},
                    </if>
                    <if test="item.visitScore !=null">
                        VISTT_SCORE = #{item.visitScore,jdbcType=INTEGER},
                    </if>
                    <if test="item.liveSource !=null">
                        LIVE_SOURCE = #{item.liveSource,jdbcType=VARCHAR},
                    </if>
                    <if test="item.liveURL !=null">
                        LIVE_URL = #{item.liveURL,jdbcType=VARCHAR},
                    </if>
                    <if test="item.isHotMatch !=null">
                        IS_HOT_MATCH = #{item.isHotMatch,jdbcType=VARCHAR}
                    </if>
                </set>
            where HOME_TEAM_ID = #{item.homeTeamId,jdbcType=VARCHAR} and
            VISIT_TEAM_ID = #{item.visitTeamId,jdbcType=VARCHAR} and
            MATCH_TIME = #{item.matchTime,jdbcType=BIGINT}
            </foreach>
        </update>

    java接口

        /**
         * 批量修改赛程
         * 
         * @param matchs
         * @throws DaoException
         */
        void updateMatchs(@Param(value = "matchs")List<MatchBasic> matchs);
  • 相关阅读:
    连通分量板子
    2017年7月17日
    强连通缩点— HDU1827
    马拉车代码
    表达式求值
    Gym-100883F、Gym-101095B状态压缩小结
    矩阵快速幂小结-Hdu2604
    3月27日
    简单移动端自适应轮播图
    上了热搜榜前端工程师面试内幕
  • 原文地址:https://www.cnblogs.com/parryyang/p/5586873.html
Copyright © 2011-2022 走看看