方法1:
主键是自增id(mysql)
在mapper文件的<insert>标签中添加useGeneratedKeys="true" keyProperty="id"
<insert id="xxx" useGeneratedKeys="true" keyProperty="id">xxxx<insert>
之后在代码中可获取:
Object o = new Object();
service.insert(o);
int id = o.getId(); //即可获取到刚刚插入的记录的id
方法2:
<insert id="insert" parameterType="vo.Category" useGeneratedKeys="true" keyProperty="id" >
insert into category (id, user_name, password,age)
values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},#{age,jdbcType=INTEGER})
</insert>