@需求:插入一条记录并返回它的主键值
@场景:有两张表:category、user_category,结构如下所示,增加分类时,要返回记录的主键值,方便插入user_category表
category
user_category
@常用方法: 在mapper的insert语句里添加 属性 :useGeneratedKeys="true" KeyProperty="id"
<insert id="addCategory" parameterType="org.rhb.bean.Category" useGeneratedKeys="true" keyProperty="id">
INSERT INTO category SET date=#{date},cateName=#{cateName}
</insert>
@如何获取返回的主键:
image.png
@结果
image.png