You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/markdown/docs/insert.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ The library will generate a variety of INSERT statements:
5
5
1. An insert for multiple rows with a single statement
6
6
1. An insert for multiple rows with a JDBC batch
7
7
1. A general insert statement
8
-
1. An insert with a select statement
8
+
1. An insert with a select statement
9
9
10
10
## Single Row Insert
11
11
A single record insert is a statement that inserts a single record into a table. This statement is configured differently than other statements in the library so that MyBatis' support for generated keys will work properly. To use the statement, you must first create an object that will map to the database row, then map object attributes to fields in the database. For example:
@@ -42,7 +42,7 @@ Notice the `map` method. It is used to map a database column to an attribute of
42
42
3.`map(column).toStringConstant(constant_value)` will insert a constant into a column. The constant_value will be written into the generated insert statement surrounded by single quote marks (as an SQL String)
43
43
4.`map(column).toProperty(property)` will insert a value from the record into a column. The value of the property will be bound to the SQL statement as a prepared statement parameter
44
44
5.`map(column).toPropertyWhenPresent(property, Supplier<?> valueSupplier)` will insert a value from the record into a column if the value is non-null. The value of the property will be bound to the SQL statement as a prepared statement parameter. This is used to generate a "selective" insert as defined in MyBatis Generator.
45
-
6.`map(column).toRow()` will insert the record itself into a column. This is appropriate when the "record" is a simple class like Integer or String.
45
+
6.`map(column).toRow()` will insert the record itself into a column. This is appropriate when the "record" is a simple class like Integer or String.
46
46
47
47
### Annotated Mapper for Single Row Insert Statements
48
48
The InsertStatementProvider object can be used as a parameter to a MyBatis mapper method directly. If you
We do not recommend using an XML mapper for insert statements, but if you want to do so the InsertStatementProvider object can be used as a parameter to a MyBatis mapper method directly.
65
65
66
66
If you are using an XML mapper, the insert method should look like this in the Java interface:
We do not recommend using an XML mapper for insert statements, but if you want to do so the MultiRowInsertStatementProvider object can be used as a parameter to a MyBatis mapper method directly.
144
144
145
145
If you are using an XML mapper, the insert method should look like this in the Java interface:
@@ -189,7 +189,7 @@ that we expect generated values. Further, note that the `keyProperty` is set to
189
189
return the `insertStatement` as supplied in the method call. The adapter method requires that there be one, and only
190
190
one, String parameter in the method call, and it assumes that this one String parameter is the SQL insert statement.
191
191
The parameter can have any name and can be specified in any position in the method's parameter list.
192
-
The `@Param` annotation is not required for the insert statement. However, it may be specified if you so desire.
192
+
The `@Param` annotation is not required for the insert statement. However, it may be specified if you so desire.
193
193
194
194
The second method above decomposes the `MultiRowInsertStatementProvider` and calls the first method.
195
195
@@ -222,7 +222,7 @@ A batch insert is a collection of statements that can be used to execute a JDBC
222
222
223
223
It is important to open a MyBatis session by setting the executor type to BATCH. The records are inserted on the commit. You can call commit multiple times if you want to do intermediate commits.
224
224
225
-
Notice that the same mapper method that is used to insert a single record is now executed multiple times. The `map` methods are the same with the exception that the `toPropertyWhenPresent` mapping is not supported for batch inserts.
225
+
Notice that the same mapper method that is used to insert a single record is now executed multiple times. The `map` methods are the same with the exception that the `toPropertyWhenPresent` mapping is not supported for batch inserts.
226
226
227
227
## General Insert Statement
228
228
A general insert is used to build arbitrary insert statements. The general insert does not require a separate record object to hold values for the statement - any value can be passed into the statement. This version of the insert is not convenient for retrieving generated keys with MyBatis - for that use case we recommend the "single record insert". However the general insert is perfectly acceptable for Spring JDBC template or MyBatis inserts that do not return generated keys. For example
We do not recommend using an XML mapper for insert statements, but if you want to do so the GeneralInsertStatementProvider object can be used as a parameter to a MyBatis mapper method directly.
266
266
267
267
If you are using an XML mapper, the insert method should look like this in the Java interface:
@@ -299,7 +299,7 @@ An insert select is an SQL insert statement the inserts the results of a select
299
299
300
300
int rows = mapper.insertSelect(insertSelectStatement);
301
301
```
302
-
The column list is optional and can be removed if the selected columns match the layout of the table.
302
+
The column list is optional and can be removed if the selected columns match the layout of the table.
303
303
304
304
### Annotated Mapper for Insert Select Statements
305
305
The InsertSelectStatementProvider object can be used as a parameter to a MyBatis mapper method directly. If you
@@ -322,7 +322,7 @@ Note that MyBatis does not support overloaded mapper method names, so the name o
322
322
We do not recommend using an XML mapper for insert statements, but if you want to do so the InsertSelectStatementProvider object can be used as a parameter to a MyBatis mapper method directly.
323
323
324
324
If you are using an XML mapper, the insert method should look like this in the Java interface:
0 commit comments