首页 > 代码库 > spring mybatis 批量插入返回主键

spring mybatis 批量插入返回主键

1.模型

public class AzTest {
private Integer id;

private Integer age;

private String title;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
}

2.mapper
void insertAll(List<AzTest> list);

3.xml

<insert id="insertAll" parameterType="AzTest" keyProperty="id" useGeneratedKeys="true">
insert into az_test(age,title)
VALUES
(#{age},#{title})
</insert>

spring mybatis 批量插入返回主键