Skip to content

Commit 3e438e1

Browse files
committed
Documentation
1 parent 681fdc6 commit 3e438e1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/site/markdown/docs/insert.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,34 @@ The XML element should look like this:
161161
```
162162

163163
### Generated Values
164-
MyBatis supports returning generated values from a multiple row insert statement with some limitations. The main limitation is that MyBatis does not support nested lists in parameter objects. Unfortunately, the `MultiRowInsertStatementProvider` relies on a nested List. It is likely this limitation in MyBatis will be removed at some point in the future, so stay tuned.
164+
MyBatis supports returning generated values from a multiple row insert statement with some limitations. The main
165+
limitation is that MyBatis does not support nested lists in parameter objects. Unfortunately, the
166+
`MultiRowInsertStatementProvider` relies on a nested List. It is likely this limitation in MyBatis will be removed at
167+
some point in the future, so stay tuned.
165168

166-
Nevertheless, you can configure a mapper that will work with the `MultiRowInsertStatementProvider` as created by this library. The main idea is to decompose the statement from the parameter map and send them as separate parameters to the MyBatis mapper. For example:
169+
Nevertheless, you can configure a mapper that will work with the `MultiRowInsertStatementProvider` as created by this
170+
library. The main idea is to decompose the statement from the parameter map and send them as separate parameters to the
171+
MyBatis mapper. For example:
167172

168173
```java
169174
...
170-
@Insert({
171-
"${insertStatement}"
172-
})
175+
@InsertProvider(type=SqlProviderAdapter.class, method="insertMultipleWithGeneratedKeys")
173176
@Options(useGeneratedKeys=true, keyProperty="records.fullName")
174-
int insertMultipleWithGeneratedKeys(@Param("insertStatement") String statement, @Param("records") List<GeneratedAlwaysRecord> records);
177+
int insertMultipleWithGeneratedKeys(String insertStatement, @Param("records") List<GeneratedAlwaysRecord> records);
175178

176179
default int insertMultipleWithGeneratedKeys(MultiRowInsertStatementProvider<GeneratedAlwaysRecord> multiInsert) {
177180
return insertMultipleWithGeneratedKeys(multiInsert.getInsertStatement(), multiInsert.getRecords());
178181
}
179182
...
180183
```
181184

182-
The first method above shows the actual MyBatis mapper method. Note the use of the `@Options` annotation to specify that we expect generated values. Further note that the `keyProperty` is set to `records.fullName` - in this case, `fullName` is a property of the objects in the `records` List.
185+
The first method above shows the actual MyBatis mapper method. Note the use of the `@Options` annotation to specify
186+
that we expect generated values. Further, note that the `keyProperty` is set to `records.fullName` - in this case,
187+
`fullName` is a property of the objects in the `records` List. The library supplied adapter method will simply
188+
return the `insertStatement` as supplied in the method call. The adapter method requires that there be one, and only
189+
one, String parameter in the method call, and it assumes that this one String parameter is the SQL insert statement.
190+
The parameter can have any name and can be specified in any position in the method's parameter list.
191+
The `@Param` annotation is not required for the insert statement. However, it may be specified if you so desire.
183192

184193
The second method above decomposes the `MultiRowInsertStatementProvider` and calls the first method.
185194

0 commit comments

Comments
 (0)