Mapper.xml主键自增

https://www.cnblo在 mapper.xml 中对于的数据库的表中,由于表设计的是主键自增,所以添加的时候不用给主键 id 赋值,数据库会自动的给 id 赋值,而怎么拿到赋值后的 id 呢,需要在 mapper.xml 中的 insert 中加入:
  useGeneratedKeys="true" keyProperty="id" //得到 id
如:
<insert id="insertSelective" parameterType="com.miaoshaproject.dataproject.UserDo" useGeneratedKeys="true" keyProperty="id">
  Insert into … //SQL语句
</insert>
这种办法,会对注入的 实体类,自动加入 id 的值。

posted @ 2020-08-31 17:19  星海寻梦233  阅读(1097)  评论(0编辑  收藏  举报