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/whereClauses.md
+54-2Lines changed: 54 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,7 @@ 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 MyBatisfeature 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 standalone where clause, you can code a mapper method that looks like this:
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:
73
73
74
74
```java
75
75
@Select({
@@ -90,4 +90,56 @@ You can build a stand alone where clause and call your mapper like this:
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.
94
+
95
+
### 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:
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.
117
+
118
+
### 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):
@Param("limit") int limit, @Param("offset") int offset);
132
+
```
133
+
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:
Notice that the string `whereSupport` is used both as the parameter name in the mapper `@Param` annotation and the parameter name in the `render` method.
144
+
145
+
The render method also has an override that accepts a TableAliasCalculator and a parameter name.
0 commit comments