title: Why does this WHERE clause work in my MyBatis mapper + Spring3 application?
body: <p>I found the below code in an example and it works. But I don't know why. </p>
  
  <p>My questions are:</p>
  
  <ul>
  <li><p>How does the mapping from <code>getDrugsWithAlert(int count)</code> get assigned to <code>#{maxrowcount}</code> (I can put anything inside: <code>#{maxrowcount}</code>, <code>#{mcount}</code> and it does not seem to matter); </p></li>
  <li><p>how/why the <code>if test="_parameter != null and _parameter &gt; 0</code> works?</p></li>
  </ul>
  
  <p>My DAO interface looks like this:</p>
  
  <pre><code>@Repository
  public interface DrugMasterDao {
      public List&lt;Drug_Master&gt; getDrugsWithAlert(int count);
  }
  </code></pre>
  
  <p>My mapper file looks like this:</p>
  
  <pre><code>&lt;mapper namespace="org.mydb.formulary.drugmaster.dao.DrugMasterDao"&gt;
  
      &lt;select id="getDrugsWithAlert" parameterType="int"  
              resultType="org.mydb.formulary.drug_master.model.Drug_Master"&gt;
  
          Select drug_id , drug_name , drug_alert_date, drug_alert_source
            from (select drug_id,drug_name,to_char(drug_alert_datetime,'MM/DD/YYYY') as
                         drug_alert_date ,drug_alert_source
                    from drug_master
                    where drug_status ='A' and length(drug_alert) &gt; 0
                    order by drug_alert_datetime DESC )
  
         &lt;if test="_parameter != null and _parameter &gt; 0"&gt;
            where rownum &amp;lt;= #{maxrowcount}
         &lt;/if&gt;
      &lt;/select&gt;
   &lt;/mapper&gt;
  </code></pre>