Skip to content

Commit 206fc3c

Browse files
authored
Creating dynamic SQL using annotations and <script>
1 parent 528d923 commit 206fc3c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/site/xdoc/dynamic-sql.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ AND title like ‘someTitle’]]></source>
156156
<p><span class="label important">NOTE</span> You can pass any Iterable object (for example List, Set, etc.), as well as any Map or Array object to foreach as collection parameter. When using an Iterable or Array, index will be the number of current iteration and value item will be the element retrieved in this iteration. When using a Map (or Collection of Map.Entry objects), index will be the key object and item will be the value object.</p>
157157
<p>This wraps up the discussion regarding the XML configuration file and XML mapping files. The next section will discuss the Java API in detail, so that you can get the most out of the mappings that you’ve created.</p>
158158
</subsection>
159+
<subsection name="script">
160+
<p>For using dynamic SQL in annotated mapper class, <em>script</em> element can be used. For example:</p>
161+
<source><![CDATA[@Update(
162+
"<script>update Author",
163+
" <set>",
164+
" <if test="username != null">username=#{username},</if>",
165+
" <if test="password != null">password=#{password},</if>",
166+
" <if test="email != null">email=#{email},</if>",
167+
" <if test="bio != null">bio=#{bio}</if>",
168+
" </set>",
169+
"where id=#{id}",
170+
"</script>")
171+
void updateAuthorValues(Author author);]]></source>
172+
</subsection>
159173
<subsection name="bind">
160174
<p>The <code>bind</code> element lets you create a variable out of an OGNL expression and bind it to the context. For example:</p>
161175
<source><![CDATA[

0 commit comments

Comments
 (0)