mybatis 做 insert操作的时候 怎么才能返回插入的那条数据的id
1个回答
展开全部
mysql:加上useGeneratedKeys="true" keyProperty="id
<insert id="add" parameterType="vo.Category" useGeneratedKeys="true" keyProperty="id">
insert into category (name_zh, parent_id,
show_order, delete_status, description
)
Oracle:加上<selectKey></selectKey>和里面的内容
<insert id="add" parameterType="vo.Category">
<selectKey resultType="java.lang.Short" order="BEFORE" keyProperty="id">
SELECT SEQ_TEST.NEXTVAL FROM DUAL
</selectKey>
<insert id="add" parameterType="vo.Category" useGeneratedKeys="true" keyProperty="id">
insert into category (name_zh, parent_id,
show_order, delete_status, description
)
Oracle:加上<selectKey></selectKey>和里面的内容
<insert id="add" parameterType="vo.Category">
<selectKey resultType="java.lang.Short" order="BEFORE" keyProperty="id">
SELECT SEQ_TEST.NEXTVAL FROM DUAL
</selectKey>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询