木木_彬

springboot+mybatis项目中配置自动增长主键

参考文章: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);

posted on 2020-05-05 11:39  木木_彬  阅读(5695)  评论(0编辑  收藏  举报