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/mybatis3.md
+52-17Lines changed: 52 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,26 +5,50 @@ The goal of this support is to reduce the amount of boilerplate code needed for
5
5
6
6
With version 1.1.3, specialized interfaces and utilities were added that can further simplify client code. This support enables the creation of methods that have similar functionality to some of the methods generated in previous versions of MyBatis generator like countByExample, deleteByExample, and selectByExample. We no longer use the "by example" terms for these methods as this library has eliminated the Example class that was generated by prior versions of MyBatis Generator.
7
7
8
-
## Dynamic Result Mapping Support
9
-
MyBatis is very good at mapping result sets to objects - this is one of its primary differentiators. MyBatis also requires
10
-
that you predefine the mappings for every possibility. This presents a challenge if you want very dynamic column lists
11
-
in a query. This library provides a generalized MyBatis mapper that can assist with that problem.
12
-
13
-
The general mapper is `org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper`. This mapper can be injected into a MyBatis configuration
14
-
as is, or it can be extended by an existing mapper. If you are using MyBatis Spring support and auto scanning for mappers,
15
-
you can create an extension in your application's mapper package as follows:
8
+
## Common Mapper Support
9
+
The library includes several common mappers for MyBatis that can be injected into a MyBatis configuration as-is, or can be
10
+
extended. These mappers can be used to eliminate repetitive boilerplate code for several operations - namely count queries,
11
+
deletes, inserts, and updates. In addition, there is a common select mapper that can be used to avoid writing custom
12
+
result maps for every query. The common select mapper provides a row mapper function that is very similar to Spring
13
+
JDBC template.
14
+
15
+
### Common Count, Delete, Insert, and Update Mappers
16
+
These mappers provide utility functions that execute simple queries. They can be used as-as, or can be extended. They
@@ -134,7 +159,10 @@ To use this support, we envision creating several methods on a MyBatis mapper in
134
159
long count(SelectStatementProvider selectStatement);
135
160
```
136
161
137
-
This is a standard method for MyBatis Dynamic SQL that executes a query and returns a `long`. The other methods will reuse this method and supply everything needed to build the select statement except the where clause. There are several variants of count queries that may be useful:
162
+
This is a standard method for MyBatis Dynamic SQL that executes a query and returns a `long`. The other methods will reuse
163
+
this method and supply everything needed to build the select statement except the where clause. In lieu of writing this method,
164
+
you could extend `org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper` instead. There are several variants
165
+
of count queries that may be useful:
138
166
139
167
1.`count(*)` - counts the number of rows that match a where clause
140
168
1.`count(column)` - counts the number of non-null column values that match a where clause
@@ -180,7 +208,9 @@ To use this support, we envision creating two methods on a MyBatis mapper interf
180
208
int delete(DeleteStatementProvider deleteStatement);
181
209
```
182
210
183
-
This is a standard method for MyBatis Dynamic SQL that executes a delete and returns an `int` - the number of rows deleted. The second method will reuse this method and supply everything needed to build the delete statement except the where clause:
211
+
This is a standard method for MyBatis Dynamic SQL that executes a delete and returns an `int` - the number of rows deleted.
212
+
In lieu of writing this method, you could extend `org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper` instead.
213
+
The second method will reuse this method and supply everything needed to build the delete statement except the where clause:
184
214
185
215
```java
186
216
defaultint delete(DeleteDSLCompleter completer) {
@@ -218,7 +248,9 @@ int generalInsert(GeneralInsertStatementProvider insertStatement);
218
248
int insertMultiple(MultiRowInsertStatementProvider<PersonRecord> insertStatement);
219
249
```
220
250
221
-
These methods are standard methods for MyBatis Dynamic SQL. They execute a single row insert, a general insert, and a multiple row insert.
251
+
These methods are standard methods for MyBatis Dynamic SQL. They execute a single row insert, a general insert, and a
252
+
multiple row insert. In lieu of writing these methods, you could extend
These methods can be used to implement simplified insert methods:
224
256
@@ -357,7 +389,10 @@ To use this support, we envision creating several methods on a MyBatis mapper in
357
389
int update(UpdateStatementProvider updateStatement);
358
390
```
359
391
360
-
This is a standard method for MyBatis Dynamic SQL that executes a query and returns an `int` - the number of rows updated. The second method will reuse this method and supply everything needed to build the update statement except the values and the where clause:
392
+
This is a standard method for MyBatis Dynamic SQL that executes a query and returns an `int` - the number of rows updated.
393
+
In lieu of writing this method, you could extend `org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper` instead.
394
+
The second method will reuse this method and supply everything needed to build the update statement except the values
0 commit comments