mybatis 批量插入,返回自增主键的主键值
请教各位达人,在mybatis3中,我要批量插入一批数据到mysql数据库,使用的foreach标签,这个表的主键是自动递增的,我想获取插入的这些数据的主键ID,请问怎么获得?用selectKey标签也获取不到。样例如下:
<insert id="saveBatchRechActivity" parameterType="java.util.List">
<selectKey keyProperty="id" resultType="int" order="AFTER">
select last_insert_id()
</selectKey>
insert into td_rech_act_conf(card_type,channel_id,rech_amount,acct_amount,gift_amount,eff_time,exp_time,act_name,introduction)
values
<foreach collection="list" item="item" separator=",">
(#{item.cardType},#{item.channelId},#{item.rechAmount}*100,#{item.acctAmount}*100,#{item.giftAmount}*100,#{item.effTime},#{item.expTime},#{item.activityName},#{item.introduction})
</foreach>
</insert>
<insert id="saveBatchRechActivity" parameterType="java.util.List">
<selectKey keyProperty="id" resultType="int" order="AFTER">
select last_insert_id()
</selectKey>
insert into td_rech_act_conf(card_type,channel_id,rech_amount,acct_amount,gift_amount,eff_time,exp_time,act_name,introduction)
values
<foreach collection="list" item="item" separator=",">
(#{item.cardType},#{item.channelId},#{item.rechAmount}*100,#{item.acctAmount}*100,#{item.giftAmount}*100,#{item.effTime},#{item.expTime},#{item.activityName},#{item.introduction})
</foreach>
</insert>
...全文
相关推荐
Mybatis使用useGeneratedKeys获取自增主键的方法
主要给大家介绍了关于Mybatis使用useGeneratedKeys获取自增主键的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Mybatis具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
详解MyBatis批量插入数据Mapper配置文件的写法
本篇文章主要介绍了详解MyBatis批量插入数据Mapper文件的写法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
mybatis-3.3.1.jar
mybatis3.3.1支持批量插入后返回主键ID,mybatis3.3.1支持批量插入后返回主键ID,
mybatis3.3.1
mybatis3.3.1的jar包 支持批量插入并返回主键
MyBatis_insert
MyBatis 映射器 insert元素 示例Demo


Web 开发
