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
The library will create classes that will be used as input to a MyBatis mapper. These classes include the generated SQL, as well as a parameter set that will match the generated SQL. Both are required by MyBatis. It is intended that these objects be the one and only parameter to a MyBatis mapper method.
99
+
The library will create classes that will be used as input to a MyBatis mapper. These classes include the generated
100
+
SQL, as well as a parameter set that will match the generated SQL. Both are required by MyBatis. It is intended that
101
+
these objects be the one and only parameter to a MyBatis mapper method.
77
102
78
-
The library can be used with both XML and annotated mappers, but we recommend using MyBatis' annotated mapper support in all cases. The only case where XML is required is when you code a JOIN statement - in that case you will need to define your result map in XML due to limitations of the MyBatis annotations in supporting joins.
103
+
The library can be used with both XML and annotated mappers, but we recommend using MyBatis' annotated mapper support in
104
+
all cases. The only case where XML is required is when you code a JOIN statement - in that case you will need to define
105
+
your result map in XML due to limitations of the MyBatis annotations in supporting joins.
Copy file name to clipboardExpand all lines: src/site/markdown/docs/whereClauses.md
+24-14
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,10 @@ Most of the conditions also support a subquery. For example:
69
69
```
70
70
71
71
## Stand Alone Where Clauses
72
-
You can use the where clause support on its own if you would rather code your own SQL for the remainder of a statement. There may be several reasons to do this - mainly if the library doesn't support some SQL or MyBatis feature you want to use. A good example would be paginated queries which are currently not support by the library. If you want to use a stand alone where clause, you can code a mapper method that looks like this:
72
+
Although rare, you can use the where clause support on its own if you would rather code your own SQL for the remainder
73
+
of a statement. There may be several reasons to do this - mainly if the library doesn't support some SQL or MyBatis
74
+
feature you want to use. A good example would be if you want to append other SQL to the generated SQL produced by the
75
+
library. If you want to use a stand alone where clause, you can code a mapper method that looks like this:
73
76
74
77
```java
75
78
@Select({
@@ -78,7 +81,7 @@ You can use the where clause support on its own if you would rather code your ow
This method works well when there are no other parameters needed for the statement and when there are no table aliases involved. If you have those other needs, then see the following.
96
+
This method works well when there are no other parameters needed for the statement and when there are no table aliases
97
+
involved. If you have those other needs, then see the following.
94
98
95
99
### Table Aliases
96
-
If you need to use a table alias in the generated where clause you can supply it on the render method using the `TableAliasCalculator` class. For example, if you have a mapper like this:
100
+
If you need to use a table alias in the generated where clause you can supply it on the render method using the
101
+
`TableAliasCalculator` class. For example, if you have a mapper like this:
97
102
98
103
```java
99
104
@Select({
@@ -102,7 +107,7 @@ If you need to use a table alias in the generated where clause you can supply it
It is more likely that you will be using table aliases with hand coded joins where there is more than on table alias. In this case, you supply a `Map<SqlTable, String>` to the TableAliasCalculator that holds an alias for each table involved in the WHERE clause.
121
+
It is more likely that you will be using table aliases with hand coded joins where there is more than on table alias.
122
+
In this case, you supply a `Map<SqlTable, String>` to the TableAliasCalculator that holds an alias for each table
123
+
involved in the WHERE clause.
117
124
118
125
### Handling Multiple Parameters
119
-
By default, the WHERE clause renderer assumes that the rendered WHERE clause will be the only parameter to the mapper method. This is not always the case. For example, suppose you have a paginated query like this (this is HSQLDB syntax):
126
+
By default, the WHERE clause renderer assumes that the rendered WHERE clause will be the only parameter to the mapper
127
+
method. This is not always the case. For example, suppose you have a paginated query like this (this is HSQLDB syntax):
120
128
121
129
```java
122
130
@Select({
@@ -127,19 +135,21 @@ By default, the WHERE clause renderer assumes that the rendered WHERE clause wil
@Param("limit") int limit, @Param("offset") int offset);
132
140
```
133
141
134
-
In this mapper method there are three parameters. So in this case it will be necessary to tell the WHERE rendered what parameter name to use the for rendered where clause. That code looks like this:
142
+
In this mapper method there are three parameters. So in this case it will be necessary to tell the WHERE rendered what
143
+
parameter name to use the for rendered where clause. That code looks like this:
Notice that the string `whereClauseProvider` is used both as the parameter name in the mapper `@Param` annotation and the parameter name in the `render` method.
152
+
Notice that the string `whereClauseProvider` is used both as the parameter name in the mapper `@Param` annotation,
153
+
and the parameter name in the `render` method.
144
154
145
-
The render method also has an override that accepts a TableAliasCalculator and a parameter name.
155
+
The render method also has an override that accepts a `TableAliasCalculator` and a parameter name.
0 commit comments