mybatis insert数据 主键返回

<insert>
			<!--selectKey将主键返回,需要再返回-->
			<selectKey keyProperty="id" order="AFTER"  resultType="java.lang.Integer">select LAST_INSERT_ID()</selectKey>
</insert>
添加selectKey标签实现主键返回。
keyProperty:指定返回的主键,存储在pojo中的哪个属性
order:selectKey标签中sql的执行顺序,是相对insert语句来说。	由于mysql的自增原理,执行完insert语句之后才将主键生成,所以这里selectKey的执行顺序为after
resultType:返回的主键对应的java类型
last_insert_id():是mysql的函数,返回auto_increment自增列新记录id值
发布了9 篇原创文章 · 获赞 1 · 访问量 185

猜你喜欢

转载自blog.csdn.net/qq_33358408/article/details/103903254
今日推荐