本文介绍了如何使用MyBatis获取Oracle中的最后一个插入ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一些数据插入到Oracle
表中,并且需要检索所插入行的id
.所述id
由一个序列生成,然后由触发器插入到表中.
I'm inserting some data into an Oracle
table and need to retrieve the id
of the inserted row. Said id
is being generated by a sequence and then inserted to the table by a trigger.
现在,我知道使用JDBC
时有几种获取插入行的ID的方法,但是由于我正在使用MyBatis
执行INSERT
命令,所以我似乎无法弄清楚插入我的数据后如何获取ID.任何建议将不胜感激.
Now, I know there are several ways to get the id of the inserted row when using JDBC
, but since I'm using MyBatis
to execute the INSERT
command, I can't seem to figure out how to obtain the id after inserting my data. Any advice would be greatly appreciated.
推荐答案
类似的方法应该起作用
class User {
int userId
...
}
<insert id="addUser" useGeneratedKeys="true" keyColumn="user_id" keyProperty="userId">
INSERT INTO user(login, name,...) VALUES(#{login}, #{name},...
</insert>
这篇关于如何使用MyBatis获取Oracle中的最后一个插入ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!