title: MyBatis extra comma in update query
body: <p>In the Mybatis xml mapper file, I tried to write update query for User table as shown below. Each of the input parameter could be null and I only update when it isn't null. You don't know which 'if' condition could fall through and which one could be the last one, thus comma has to be added in each statement. </p>
  
  <p>The problem is that the extra ',' causes query exception. It seems Mybatis doesn't ignore extra comma. </p>
  
  <p>My workaround is to put "id = #{id}" at the end which fixed the problem but it is redundant. </p>
  
  <p>What is the real solution?</p>
  
  <p>The code:</p>
  
  <pre><code>&lt;update id="update" parameterType="User"&gt;
      UPDATE user SET
  
      &lt;if test="username != null"&gt;
          username = #{username},
      &lt;/if&gt;
      &lt;if test="password != null"&gt;
          password = #{password},
      &lt;/if&gt;
      &lt;if test="email != null"&gt;
          email = #{email},
      &lt;/if&gt;
      id= #{id} // this is redundant
  
      WHERE id = #{id}
  &lt;/update&gt;
  </code></pre>
  
  <p>PS: The environment I am using is: Java Spring + MyBatis + MySQL.</p>