title: How to use <foreach> statement in @SelectProvider class with MyBatis3
body: <p>I am trying to use <code>@SelectProvider</code> to create dynamic SQL by including the use of the tag <code>foreach</code> for a <code>IN</code> clause. I know how to use it using the <code>@Select</code> annotation into my mapper.</p>
  
  <p>The problem is that when I translate the SQL into the SQLProvider it seem that the use it of the tag directly is not processed for the proxy that invoke SQLProvider method to get the SQL.</p>
  
  <p>Here is the code example by using the <code>@Select</code>:</p>
  
  <pre><code>// imports...
  
  public interface MyMapper {
      @Select({"&lt;script&gt;",
          "SELECT col_1, col_2", 
          "FROM table_1",
          "WHERE col_3 IN",
              "&lt;foreach item='item' index='index' collection='items'",
                  "open='(' separator=',' close=')'&gt;",
                  "#{item}",
              "&lt;/foreach&gt;",
          "&lt;/script&gt;"})
      HashMap&lt;String, Object&gt; select(@Param("items") String[] items);
  }
  </code></pre>
  
  <p>The code above actually works, but when I try to use the <code>@SelectProvider</code> it doesn't works.</p>
  
  <p>This is the code when I use @SelectProvider:</p>
  
  <pre><code>// imports...
  
  public interface MyMapper {
      @SelectProvider(type = MySQLProvider.class, method = "select")
      HashMap&lt;String, Object&gt; select(@Param("items") String[] items);
  }
  
  public class MySQLProvider {
      public String select() {
          SQL sql = new SQL();
          sql.SELECT("col_1");
          sql.SELECT("col_2");
          sql.FROM("table_1");
          sql.WHERE("col_3 IN"
              + "&lt;foreach item='item' index='index' collection='items'"
                  + "open='(' separator=',' close=')'&gt;"
                  + "#{item}"
              + "&lt;/foreach&gt;");
          return "&lt;script&gt;" + sql.toString() + "&lt;/script&gt;";
      }
  }
  </code></pre>
  
  <p>When I use the <code>MyMapper</code> it process the SQL well but ignore the <code>script</code> and <code>foreach</code> statements.</p>
  
  <p>Could anyone provide a concrete solution including the code?</p>