mybatis批量插入返回主键id

最近项目需要批量插入一批数据,然后根据这批数据的id,再插入关联表;

需要使用mybatis的版本为3.3.1,之前使用3.2.8的没返回主键id

参考:https://github.com/mybatis/mybatis-3/pull/547

service层:

public void saveDeskBatch(List<ShopDeskSortDto> shopDeskSortDtoList) {
        List<ShopDeskSort> shopDeskSortList = new ArrayList<ShopDeskSort>();
        shopDeskSortList = CollectionUtils.transform(shopDeskSortDtoList, ShopDeskSort.class);
        shopDeskSortMapper.saveBatch(shopDeskSortList);
}

 

xml文件

<insert id="saveBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        <![CDATA[
            INSERT INTO shop_desk_sort (
                id,
                name,
                parent_id,
                shop_id
            ) VALUES
        ]]>
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.id},#{item.name},#{item.parentId},#{item.shopId})
        </foreach>
    </insert>

 

比之前单个插入速度得到明显提升,飞起。。。

 

2017年3月12日10:58:11

升级3.3.1之后,项目出现许多不兼容。。。

 

posted @ 2017-03-10 12:30  乱码出黑客  阅读(1755)  评论(0编辑  收藏  举报