场景:orm框架用mybatis,需要往数据库新增一条数据,用Oracle和mysql数据库分别需要怎么实现?
mysql方法,用mysql提供的uuid函数
<insert id="add" parameterType="com.t.model.ActionModel" databaseId="mysql">
insert into t_config
(uuid, `condition`, flag, create_time, project_name,tips,status,tf_name,parent_flag)
values
(uuid(),#{condition},#{flag},#{createTime},#{projectName},#{tips},#{status},#{tfName},#{parentFlag})
</insert>
oracle方法,主要用神奇的dual,select sys_guid() from dual
<insert id="add" parameterType="com.t.model.ActionModel" databaseId="oracle">
<selectKey keyProperty="uuid" resultType="java.lang.String" order="BEFORE">
select sys_guid() from dual
</selectKey>
insert into t_config
(uuid, condition, flag, create_time, project_name,tips,status,tf_name,parent_flag)
values
(#{uuid},#{condition},#{flag},#{createTime},#{projectName},#{tips},#{status},#{tfName},#{parentFlag})
</insert>
网友评论