zoukankan      html  css  js  c++  java
  • mybatis 批量插入/批量修改的写法

    1、jdbc链接修改

    jdbc.driver=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&rewriteBatchedStatements=true
    jdbc.username=root
    jdbc.password=root

    2、批量插入

         <insert id="INSERT_BATCH_HOTEL_REAL_PRICE" parameterType="java.util.List">
            INSERT IGNORE INTO VST_HOTEL_REAL_TIME_PRICE ( 
                PRODUCT_ID, 
                REAL_TIME_PRICE1, 
                REAL_TIME_PRICE2, 
                REAL_TIME_REMAIN1, 
                REAL_TIME_REMAIN2,
                UPDATE_TIME
            ) VALUES
            <foreach collection="list" item="item" index="index" separator=",">
                (#{item.productId}, 
                 #{item.realTimePrice1}, 
                 #{item.realTimePrice2}, 
                 #{item.realTimeRemain1}, 
                 #{item.realTimeRemain2},NOW())
            </foreach>
         </insert>

    3、批量修改

         <update id="UPDATE_HOTEL_REAL_TIME_PRICE" parameterType="java.util.List">
            <foreach collection="list" item="item" index="index" separator=";">
                UPDATE VST_HOTEL_REAL_TIME_PRICE
                <set>
                    <if test="item.realTimePrice1 != null">
                        REAL_TIME_PRICE1 = #{item.realTimePrice1},
                    </if>
                    <if test="item.realTimePrice2 != null">
                        REAL_TIME_PRICE2 = #{item.realTimePrice2},
                    </if>
                    <if test="item.realTimeRemain1 != null">
                        REAL_TIME_REMAIN1 = #{item.realTimeRemain1},
                    </if>
                    <if test="item.realTimeRemain2 != null">
                        REAL_TIME_REMAIN2 = #{item.realTimeRemain2},
                    </if>
                    UPDATE_TIME = NOW()
                </set>
                WHERE PRODUCT_ID = ${item.productId}
             </foreach>
         </update>

    。。。

  • 相关阅读:
    简单测试
    纸玫瑰
    Java 字符串编码 (保存成txt测试)
    创建 Filter
    jee中文名图片+tomcat ==> 中文乱码的另类处理(未成功)
    dom4j_01_02
    dom4j_01_01
    Java 字符串编码
    websocket

  • 原文地址:https://www.cnblogs.com/zhanh247/p/11510511.html
Copyright © 2011-2022 走看看