title: Reusing dynamic sql fragments
body: <p>Hei there, I'm working on a Primefaces app and as a persistence layer I chose <a href="http://mybatis.github.io/mybatis-3/" rel="nofollow">Mybatis</a>.</p>
  
  <p>This is how a regular sql would look in my mapper:</p>
  
  <pre><code>&lt;select id="getAllTransportUnit" resultMap="TransportUnitMap"&gt;
      SELECT * FROM SSLS_GUI.VW_TU
      &lt;if test="( hasFilters == 'yes' ) and ( parameters != null )"&gt;
          &lt;where&gt;
              &lt;foreach item="clause" collection="parameters" separator=" AND "
                  open="(" close=")"&gt;
                  UPPER(${clause.column}) ${clause.operator} #{clause.value}
              &lt;/foreach&gt;
          &lt;/where&gt;
      &lt;/if&gt;
      &lt;if test="sort == 'true'"&gt;
          ORDER BY ${sortField}
          &lt;if test="sortOrder == 'DESC'"&gt; DESC&lt;/if&gt;
          &lt;if test="sortOder == 'ASC'"&gt; ASC&lt;/if&gt;
      &lt;/if&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Almost all my queries use the dynamic sql part starting from the <code>&lt;if test...&gt;</code>. Is it possible to put it in a separate file and then reuse it all over my queries?</p>