title: MyBatis if clause
body: <p>I tried following if clause in MyBatis and got following exception please help me to identify the issue here..</p>
  
  <pre><code>public class Student{
  
  private Integer studId;
  private String name;
  private String email;
  private Date dob;
  }
  </code></pre>
  
  <p>Mapping</p>
  
  <pre><code>&lt;select id="searchStudent" parameterType="hashmap" resultMap="StudentResult"&gt;
      &lt;![CDATA[
      SELECT * FROM STUDENTS
      WHERE 1 = 1 
  
      &lt;if test="studId != null"&gt;
      AND STUD_ID= #{studId}
      &lt;/if&gt;
  
      &lt;if test="name != null"&gt;
      AND NAME like #{name}
      &lt;/if&gt;
  
      ]]&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Exception I get:</p>
  
  <pre><code>Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
  ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL   syntax; check the manual that corresponds to your MySQL server version for the right syntax   to use near 'test="studId != null"&gt;
      AND STUD_ID= 1
      &lt;/if&gt;
  
      &lt;if test="name != null"&gt;
      ' at line 4
  ### The error may exist in StudentMapper.xml
  ### The error may involve com.maventest.mytest.StudentMapper.searchStudent-Inline
  ### The error occurred while setting parameters
  ### SQL: SELECT * FROM STUDENTS   WHERE 1 = 1       &lt;if test="studId != null"&gt;   AND STUD_ID= ?   &lt;/if&gt;      &lt;if test="name != null"&gt;   AND NAME like ?   &lt;/if&gt;
  ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test="studId != null"&gt;
      AND STUD_ID= 1
      &lt;/if&gt;
  
      &lt;if test="name != null"&gt;
      ' at line 4
  at    org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
  </code></pre>