Skip to content

Commit

Permalink
Merge pull request mybatis#1 from rikiel/patch-1
Browse files Browse the repository at this point in the history
Creating dynamic SQL using annotations and <script>
  • Loading branch information
rikiel authored Jun 17, 2019
2 parents abd5e49 + 753e781 commit 7ed3c14
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/site/xdoc/dynamic-sql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ AND title like ‘someTitle’]]></source>
<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>
<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>
</subsection>
<subsection name="script">
<p>For using dynamic SQL in annotated mapper class, <em>script</em> element can be used. For example:</p>
<source><![CDATA[@Update(
"<script>update Author",
" <set>",
" <if test="username != null">username=#{username},</if>",
" <if test="password != null">password=#{password},</if>",
" <if test="email != null">email=#{email},</if>",
" <if test="bio != null">bio=#{bio}</if>",
" </set>",
"where id=#{id}",
"</script>")
void updateAuthorValues(Author author);]]></source>
</subsection>
<subsection name="bind">
<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>
<source><![CDATA[
Expand Down

0 comments on commit 7ed3c14

Please sign in to comment.