Mybatis批量插入返回自增主键

1.xml格式(重点这几个useGeneratedKeys="true" keyProperty="id"
        parameterType="java.util.List"

        useGeneratedKeys="true" keyProperty="id"
        parameterType="java.util.List"
>
    insert into quest_node (quest_id,quest_node_request,node_code,
    node_name, creater, creater_org,
    assigned, assigned_org, start_date,
    end_date, priority, urgency,
    importance, difficulty,
    quest_attachment, is_regular, regular_type,
    frequency, frequency_start, duration,
    create_date_time, last_update_time, last_update_by,
    enabled,mark)
    values
   
        (#{item.questId},#{item.questNodeRequest},CONCAT(#{item.nodeCode},#{item.nodeCode}),#{item.nodeName},
        #{item.creater},#{item.createrOrg},#{item.assigned},
        #{item.assignedOrg},str_to_date(#{item.startTime},'%Y-%m-%d %H:%i:%s'),str_to_date(#{item.endTime},'%Y-%m-%d
        %H:%i:%s'),
        #{item.priority},#{item.urgency},#{item.importance},#{item.difficulty},
        #{item.questAttachment}, #{item.isRegular},#{item.regularType},#{item.frequency},
        #{item.frequencyStart},#{item.duration},NOW(),NOW(),#{item.creater},1,1)
   

2.dao层

 

int insertNewNode(List list);

 3.mybatis版本3.3.1以上

4.,返回结果已经在list 中 循环list然后就可以取 id

你可能感兴趣的:(Mybatis)