Ibatis Annotations Annotation method returns the value of the self-growing primary key ID just inserted

Source: Internet
Author: User

MyBatis provides annotated way to write SQL, eliminating the hassle of configuring and writing XML mapper file, today encountered the problem of getting the return value of the primary key from the growth, found that the relevant questions and answers are relatively small, fortunately, the final solution is a complete, now focus on the record, the key to solve the problem is the following lines of code:

1     @Insert ("Insert into Product (title, image, Price, detail, summary, seller) VALUES (#{title},#{image},#{price},#{detail} , #{summary},#{seller}) ")2     @Options (usegeneratedkeys=true, keyproperty=" id ")/ / Add the line, the ID in product will be automatically added 3public      Integer insertproduct (product product);

Add the second line above, where the second parameter is said to be

After you add the note

When you add a success to the database, the ID property of the product is assigned the default value.

Ibatis Annotations Annotation method returns the value of the self-growing primary key ID just inserted

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.