<insert id="preserveStudent" parameterType="com.model.Student" useGeneratedKeys="true">
insert into Student(name,phone,grade,teacher,hobby,sex)
values
(#{name},#{phone},#{grade},#{teacher},#{hobby},#{sex})
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
</insert>
controller写法:
studentService.preserveStudent(student);//执行service方法
int id=student.getId();//返回的id是在pojo中去取。