标签:需要 param min ace 主键 div bat type style
需求:使用批量插入后,需要insert之后的每一条记录的ID
注意:Mybatis3.3.1的版本以后支持批量插入后返回主键ID
示例:
domin.java:
public class User { private int d; private String name; private String pwd; public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } }
mapper.java:
public interface UserMapper{ int insertTest(List<User> user); }
mapper.xml:
<insert id="insertTest" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> insert into user (name,pwd) values <foreach collection="list" item="item" index="index" separator=","> (#{item.name},#{item.pwd}) </foreach> </insert>
标签:需要 param min ace 主键 div bat type style
原文地址:https://www.cnblogs.com/JoeyWong/p/9360628.html