MyBatis获取 insert 返回的主键
如题 获取insert返回主键在MyBatis中一共两种方法
这两个方法分别如下
<insert id="insert" parameterType="com.sdj.bean.Phone" useGeneratedKeys="true" keyProperty="id">
<selectKey keyProperty="id" keyColumn="id" order="AFTER" resultType="integer">
select last_insert_id()
</selectKey>
insert into phone (id, name, content, price)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL})
</insert>
<insert id="insert" parameterType="com.sdj.bean.Phone" useGeneratedKeys="true" keyProperty="id">
insert into phone (id, name, content, price)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL})
</insert>