mybatis 一种高效的批量插入

<insert id="insertByBatch" useGeneratedKeys="false">
  	<!-- selectkey这段代码不加,会报sql错误
  	<selectKey resultType="int" keyProperty="id" order="BEFORE"> 
        SELECT 1 FROM DUAL 
    </selectKey>
    -->
  	insert into TBL_GIFT_TIMESEND_ROSTERINFO (
  		ROSTER_NAME,
  		SEND_ID,
  		USER_ACCOUNT,
        GIFTPACKAGES_ID,
        GAME_ID,
        AREA_ID,
		SERVER_ID,
		SEND_NUM,
		GAME_NAME,
		AREA_NAME,
		SERVER_NAME)
    
    <foreach collection="list" item="item" index="index" separator="UNION ALL">    
	    SELECT
	    	#{item.rosterName},
	    	#{item.sendId},
	    	#{item.userAccount},
			#{item.giftpackagesId},
			#{item.gameId},
			#{item.areaId},
			#{item.serverId},
			#{item.sendNum},
			#{item.gameName},
			#{item.areaName},
			#{item.serverName}
		FROM DUAL
	</foreach>
  </insert>

猜你喜欢

转载自wentao365.iteye.com/blog/1929390