title: In mybatis how to elegantly check parameter before execute real sql?
body: <p>For example there is a dao like this:</p>
  
  <pre><code>void batchInsert(List&lt;User&gt; userList); 
  List&lt;User&gt; getUsersByIds(List&lt;Long&gt; idList); 
  void deleteUsersByids(List&lt;Long&gt; idList); 
  </code></pre>
  
  <p>If the parameter of List is empty, then will throw exception,because the sql is wrong.eg,</p>
  
  <pre><code>mysql&gt; select * from tb_user where id in () ;
  ERROR 1064 (42000): 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 ')' at line 1
  </code></pre>
  
  <p>As a developer I don't want to care this. If the paramter is null(or empty), just return, dont't go ahead to execute the sql.</p>
  
  <p>By tracking mybatis source code, I find a method.
  That is modify source code of org.mybatis.spring.SqlSessionTemplate. For example,
  we can add the check parameter logic in selectList:</p>
  
  <pre><code> public &lt;E&gt; List&lt;E&gt; selectList(String statement, Object parameter) {
    if(parameter instanceof List){
        if(((List) parameter).isEmpty()){
          List&lt;E&gt; result =  new ArrayList&lt;&gt;();
          return result;
        }
    }
  return this.sqlSessionProxy.&lt;E&gt; selectList(statement, parameter);
  </code></pre>
  
  <p>}</p>
  
  <p>and could do like so in update,delete,insert methods. But I feel this method is not good. So I'd like to know if there is some better method for this requirement? </p>