大体总结有两个方法:
一、如果数据库指定了主键自增长:
1、在实体类的映射文件 "*Mapper.xml" 文件中:
<insert id="insert" parameterType="com.go.model.User">
<selectKey resultType="java.lang.Long" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>
insert into user(userName,password,comment)values(#{userName},#{password},#{comment})
</insert>
注释:
<insert></insert>中没有resultType属性,但<selectKey></selectKey> 标签是有的,