使用<selectKey>标签来获取插入操作主键返回的值。
对于MySQL数据库:
<insert id="insert">
insert into user(
username, password, email, info, headImg, createTime)
values(
#{username}, #{password}, #{email},
#{info}, #{headImg, jdbcType=BLOB},
#{createTime, jdbcType=TIMESTAMP})
<selectKey keyColumn="id" resultType="long" keyProperty="id" order="AFTER">
SELECT LAST_INSERT_ID()
</selectKey>
</insert>