Sometimes we need to insert a later data, hoping to return it to a primary key information, provides us MyBatis underlying this approach
1: tags implemented by selectKey
<insert id="insertStudent">
insert into student(name,email,age)
values(#{name},#{email},#{age})
<selectKey keyProperty="id" resultType="java.lang.Integer">
select LAST_INSERT_ID() as id
</selectKey>
</insert>
This method should be noted, the incoming parameter is not available @Param modified
2: to achieve by insert tags
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
insert into student(name,email,age)
values(#{name},#{email},#{age})
</insert>
Such a method is more concise