mybatis 一种高效的批量插入实例



mybatis 一种高效的批量插入实例。

Java代码 复制代码 收藏代码
  1. <insert id=”insertByBatch” useGeneratedKeys=”false”>   
  2.     <!– selectkey这段代码不加,会报sql错误   
  3.     <selectKey resultType=”int” keyProperty=”id” order=”BEFORE”>    
  4.         SELECT 1 FROM DUAL    
  5.     </selectKey>   
  6.     –>   
  7.     insert into TBL_GIFT_TIMESEND_ROSTERINFO (   
  8.         ROSTER_NAME,   
  9.         SEND_ID,   
  10.         USER_ACCOUNT,   
  11.         GIFTPACKAGES_ID,   
  12.         GAME_ID,   
  13.         AREA_ID,   
  14.         SERVER_ID,   
  15.         SEND_NUM,   
  16.         GAME_NAME,   
  17.         AREA_NAME,   
  18.         SERVER_NAME)   
  19.        
  20.     <foreach collection=”list” item=”item” index=”index” separator=”UNION ALL”>       
  21.         SELECT   
  22.             #{item.rosterName},   
  23.             #{item.sendId},   
  24.             #{item.userAccount},   
  25.             #{item.giftpackagesId},   
  26.             #{item.gameId},   
  27.             #{item.areaId},   
  28.             #{item.serverId},   
  29.             #{item.sendNum},   
  30.             #{item.gameName},   
  31.             #{item.areaName},   
  32.             #{item.serverName}   
  33.         FROM DUAL   
  34.     </foreach>   
  35.   </insert>