有两种方式
第一种:
<insert id="insert" parameterType="vo.Category" >
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
insert into category(id, user_name, password,age)
values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},#{age,jdbcType=INTEGER})
</insert>
第二种:
<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>
转载自: 点击打开链接