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

相关文章: