title: How to intercept and change sql query dynamically in mybatis
body: <p>I use mybatis to perform sql queries in my project. I need to intercept sql query before executing to apply some changed dynamically. I've read about @Interseptors like this:</p>
  
  <pre><code>@Intercepts({@Signature(type= Executor.class, method = "query", args = {...})})
  public class ExamplePlugin implements Interceptor {
    public Object intercept(Invocation invocation) throws Throwable {
      return invocation.proceed();
    }
    public Object plugin(Object target) {
      return Plugin.wrap(target, this);
    }
    public void setProperties(Properties properties) {
    }
  }
  </code></pre>
  
  <p>And it really intercepts executions, but there is no way to change sql query since appropriate field is not writable. Should I build new instance of whole object manually to just replace sql query? Where is the right place to intercept query execution to change it dynamically? Thank.</p>