@Insert(" insert into table(c1,c2) " + " values (#{c1},#{c2}) ") @SelectKey(resultType = long.class,keyColumn = "id",before = false,statement = "SELECT LAST_INSERT_ID() AS id",keyProperty = "id")
int addQuestion(Instance instance); /** public class Instance{ private long id; private String c1; private String c2; } **/
before = false: Because mysql support from growth in the primary key, it runs the insert statement, then get the primary key value from growth.
keyColumn: field names from the growth of the primary key
keyProperty: storing the corresponding entity class field, data type, and attention consistent resultType
statement: sql statement is actually executed
There is the value of the entity class SelectKey returned, thread-safe, so regardless of the success of id will be inserted into the safety increment
Another good document: HTTPS: //blog.csdn.net/xu1916659422/article/details/77921912
----------------
Disclaimer: This article is CSDN bloggers' charlieshawn "the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_41810184/article/details/81011023