mysql - MyBatis-Spring insert a list of objects and retrieve their new IDs -


i working mybatis-spring , mysql database. currently, inserting lists 1 of tables using following code:

<insert id="insertlist" parametertype="java.util.list" usegeneratedkeys="true">         insert mytable (field1, field2, field3)         values         <foreach collection="list" item="item" separator=",">             (#{item.field1}, #{item.field2}, #{item.field3})         </foreach>     </insert> 

at point, return the new ids generated after inserting new items without making new query: select * mytable.

is possible? in advance.

if list size not large, loop insert in java code

for(bean bean : list){    list.insert(bean); } 

in mapper.xml insert method should add

<selectkey keyproperty="id" order="after" resulttype="java.lang.integer">     select last_insert_id() </selectkey> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -