Mybaties插入生成UUID并返回主键
PGSQL
PGSQL
<insert id="insertData" parameterType="Object">
<selectKey resultType="long" keyProperty="Object_id">
select uuid_generate_v4();
</selectKey>
insert...语句
</insert>
ORACLE在这里插入代码片
<insert id="AltName.insert" parameterType="AltName">
<selectKey keyProperty="id" resultType="String" order="BEFORE">
select sys_guid() from dual
</selectKey>
insert into ...
</insert>
MYSQL
<insert id="insert" parameterType="com.mawulou.model.Functions" >
<selectKey keyProperty="pkGlobalId" resultType="String" order="BEFORE">
select uuid() from dual
</selectKey>
insert into ...
</insert>
MyBatis生成UUID主键
本文介绍在MyBatis中使用三种不同数据库(PGSQL、ORACLE、MYSQL)进行插入操作时,如何生成UUID作为主键并返回。通过<selectKey>元素在插入前获取UUID,确保每条记录的唯一性。
21万+

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



