参考文章:https://www.jianshu.com/p/45da254ff497
1.在dao层添加注解:@Options(useGeneratedKeys = true, keyProperty = "id");其中 keyProperty = "id"中的id为实体类中对应表中自动增长注解的字段的属性。
2.代码示例如下:
@Insert("insert into claim_voucher(cause,create_sn,create_time,next_deal_sn,total_amount,status) values(#{cause},#{createSn},#{createTime},#{nextDealSn},#{totalAmount},#{status})")
@Options(useGeneratedKeys = true, keyProperty = "id")
void insert(ClaimVoucher claimVoucher);
springboot+mybatis项目中配置自动增长主键
原文:https://www.cnblogs.com/yangyinbin/p/12830038.html