Inserts the attribute detailed explanation
ParameterType, fully qualified class name or type alias of the argument
KeyColumn, sets the primary key name that is automatically generated by the datasheet. For a specific database (such as PostgreSQL), if the Auto-generated primary key is not the first field, you must set the
Keyproperty, the default value unset, to set the Getgeneratedkeys method or Selectkey child element return value to be assigned to which property of the domain model
Usegeneratedkeys, True|false (the default), sets whether to use the Getgenereatedkeys method of JDBC to get the primary key and assign it to the domain model properties set by Keyproperty. MySQL and SQL Server execute the auto-generated key field, so when the database is set up from the growth primary key, it can be obtained through the JDBC Getgeneratedkeys method. But databases such as Oralce, which do not support the Auto-generated key field, cannot get the primary key in this way.
StatementType, Value range statement,prepared (default), callable
Flushcache, Value range True (default) |false, set whether the two level cache and local cache are emptied after the operation is performed
Timeout, defaults to unset (dependent on the JDBC drive settings), sets the maximum time limit for performing the operation, and the timeout throws an exception
DatabaseId, value range oracle|mysql, etc., for database manufacturers, within the element can be "<if test=" _databaseid = ' Oracle ' > ' to specify different SQL statements for a particular database
Second, Mapper interface
Third, perform mapper.xml return primary key
Both approaches satisfy demand.
Note: The Mapper interface return value is still the number of records that were successfully inserted, but the difference is that the primary key value has been assigned to the ID of the domain model entity.
Iv. test Results
Six, BULK Insert
<insert id= "Add" parametertype= "Com.test.model.Course" >
Insert into Tb_course (Course_name, Teacher_name,
Course_week, Course_time, place,
gmt_create, gmt_modify)
values (#{coursename,jdbctype=varchar}, #{teachername,jdbctype=varchar},
#{courseweek,jdbctype=varchar} , #{coursetime,jdbctype=varchar}, #{place,jdbctype=varchar},
#{gmtcreate,jdbctype=timestamp}, #{gmtModify, Jdbctype=timestamp})
</foreach></insert>
Vii. Summary
Two different ways
1, add Property usegeneratedkeys= "true" keyproperty= "id"
2, add code
<selectkey resulttype= "Java.lang.Short" order= "after" keyproperty= "id" >
SELECT last_insert_id () as ID
</selectKey>
It is recommended to use the first type.