MyBatis return primary key value after Oracle inserts an object

Source: Internet
Author: User

When a record is inserted by default in MyBatis, the return value is the number of bars inserted in the record.

Now you want to get the primary key value of the record that is currently being inserted after inserting the record, add the following code to the Insert method:


<insert id= "Insert" parametertype= "Cn.com.pm.ppm.model.UserInfo" >

<selectkey resulttype= "Java.math.BigDecimal" order= "before" keyproperty= "id" >

Select T_user_info_seq.nextval from dual

</selectKey>

INSERT INTO T_user_info

<trim prefix= "(" suffix= ")" suffixoverrides= "," >

<IF test= "id! = NULL" >

Id

</if>

...

</insert>


After you add the following code

<selectkey resulttype= "Java.math.BigDecimal" order= "before" keyproperty= "id" >

Select T_user_info_seq.nextval from dual

</selectKey>

The return value obtained in the method is still the number of records inserted

But MyBatis set the primary key value to the inserted object

This article is from the "Dream Escape" blog, please be sure to keep this source http://pinmei.blog.51cto.com/7012784/1628029

MyBatis return primary key value after Oracle inserts an object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.