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