<insert id="insertBatchInterest" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
insert into xxxxx ( `uid`)
values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.uid,jdbcType=INTEGER} )
</foreach>
</insert>
@Test
public void test() {
List<CouponInterestPO> batchList = new ArrayList<>();
CouponInterestPO po = new CouponInterestPO();
po.setUid(111);
batchList.add(po);
po = new CouponInterestPO();
po.setUid(222);
batchList.add(po);
couponInterestDao.insertBatchInterest(batchList);
for (CouponInterestPO c : batchList) {
LOG.info("返回主键====>"+c.getId());
}
mybatis
的3.4.1测试成功的,测试结果如上图
mybatis
的3.27的版本是不支持的会报错
org.apache.ibatis.binding.BindingException: Parameter 'id' not found.
Available parameters are [list]