Skip to content

Commit de8e6bb

Browse files
committed
Release 1.1. Added docs into README about auto-generated parameters.
1 parent 10adf96 commit de8e6bb

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mybatis-freemarker is available in [jcenter](https://bintray.com/bintray/jcenter
3232
<dependency>
3333
<groupId>org.mybatis.scripting</groupId>
3434
<artifactId>mybatis-freemarker</artifactId>
35-
<version>1.0</version>
35+
<version>1.1</version>
3636
</dependency>
3737
</dependencies>
3838
```
@@ -45,7 +45,7 @@ repositories {
4545
}
4646
4747
dependencies {
48-
compile("org.mybatis.scripting:mybatis-freemarker:1.0")
48+
compile("org.mybatis.scripting:mybatis-freemarker:1.1")
4949
}
5050
```
5151

@@ -156,6 +156,37 @@ As in annotations, you can write inline scripts or template names.
156156
</select>
157157
```
158158

159+
## Prepared statements parameters
160+
161+
`<@p/>` directive can be used in two scenarios:
162+
163+
- To pass parameters to prepared statements AS IS:
164+
165+
`<@p name='id'/>` (will be translated to `#{id}`, and value already presents in parameter object)
166+
167+
- To pass any value as prepared statements parameter
168+
169+
`<@p value=someValue/>` will be converted to `#{_p0}`, and `_p0` parameter will be automatically added to parameters map. It is convenient to use in loops like this:
170+
171+
```ftl
172+
select * from names where firstName in (
173+
<#list ids as id>
174+
<@p value=id/>
175+
<#if id_has_next>,</#if>
176+
</#list>
177+
)
178+
```
179+
180+
This markup will be translated to
181+
182+
```sql
183+
select * from names where firstName in (#{_p0}, #{_p1}, #{_p2})
184+
```
185+
186+
and there are no need to care about escaping. All this stuff will be done automatically by JDBC driver.
187+
188+
Unfortunately, you can't use this syntax if passing one object as parameter and without `@Param` annotation. The `UnsupportedOperationException` will be thrown. It is because appending additional parameters to some object in general is very hard. When you are using `@Param` annotated args, MyBatis will use `Map` to store parameters, and it is easy to add some generated params. So, if you want to use auto-generated prepared parameters, please don't forget about `@Param` annotation.
189+
159190
## Examples
160191

161192
You can view full-featured example of configuring and of both XML-mapper and annotations-driven mapper usage in [test suite](https://github.com/elw00d/mybatis-freemarker/tree/master/src/test)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.mybatis.scripting</groupId>
88
<artifactId>mybatis-freemarker</artifactId>
9-
<version>1.0</version>
9+
<version>1.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>MyBatis FreeMarker</name>

0 commit comments

Comments
 (0)