方法一:
<insert id="save" parameterType="com.example.demo.entity.User"> INSERT INTO t_student(name, sex, age) VALUES(#{name}, #{sex}, #{age}) <selectKey resultType="Integer" keyColumn="id" keyProperty="id" order="AFTER"> SELECT LAST_INSERT_ID() AS id </selectKey> </insert>
方法二:
<insert id="save" parameterType="com.example.demo.entity.User" keyProperty="id" keyColumn="id" useGeneratedKeys="true"> INSERT INTO t_student(name, sex, age) VALUES(#{name}, #{sex}, #{age}) </insert>
注意:本文归作者所有,未经作者允许,不得转载