mybatis中参数userGeneratedKeys使用
userGeneratedKeys
使用MyBatis往MySQL数据库中插入一条记录,主键自增,在mapper中指定keyProperty属性。
使用
useGeneratedKeys=“true” ,uuid代表插入的Student对象的主键属性。
<insert id="insert" parameterType="com.XX.XX.entity.Student" useGeneratedKeys="true" keyProperty="uuid">
insert into student(uuid,name,sex,class)values(#{uuid,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{sex,jdbcType=TINYINT},#{class,jdbcType=VARCHAR})</insert>
注意
这个属性只能用在主键能自增长的数据库里面比如MySQL可以用,但是oracle就不能用了。
本文介绍在MyBatis中如何利用userGeneratedKeys属性实现主键自增功能,并提供了一个具体的例子说明如何配置使用该属性。需要注意的是,此功能仅适用于支持主键自增的数据库如MySQL。
2656

被折叠的 条评论
为什么被折叠?



