import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.scripting.defaults.DefaultParameterHandler;
import java.util.Map;
import java.util.Properties;
@Intercepts({@Signature(
type= Executor.class,
method = "selectList",
args = {MappedStatement.class,Integer.class})})
public class ExamplePlugin implements Interceptor {
private Properties properties = new Properties();
public Object intercept(Invocation invocation) throws Throwable {
// implement pre processing if need
Object returnObject = invocation.proceed();
// implement post processing if need
return returnObject;
}
@Override
public Object plugin(Object o) {
if(o instanceof ParameterHandler){
DefaultParameterHandler defaultParameterHandler= (DefaultParameterHandler) o;
Map paramMap= (Map) defaultParameterHandler.getParameterObject();
System.out.println("12345");
}
return o;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
}
mybatis-config.xml中配置
<settings> <setting name="callSettersOnNulls" value="true"/> <setting name="jdbcTypeForNull" value="NULL" /> </settings>