我在mybati-config.xml中定义了两个拦截器。
<plugins>
<plugin interceptor="cn.common.interceptor.DbInterceptor"/>
<plugin interceptor="cn.common.interceptor.MybatisInterceptor"/>
</plugins>执行两个拦截器。
@Intercepts(value = {
@Signature (type=Executor.class, method="update", args = { MappedStatement.class, Object.class })})
public class DbInterceptor implements Interceptor {
private Properties properties;
@Override
public Object intercept(Invocation invocation) throws Throwable {
System.out.println("db interceptor invoke");
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
this.properties = properties;
}
}
@Intercepts({
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
public class MybatisInterceptor implements Interceptor {
private Properties properties;
@Override
public Object intercept(Invocation invocation) throws Throwable {
System.out.println("mybatis interceptor invoke");
return invocation.proceed();
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
this.properties = properties;
}
}MybatisInterceptor在我执行update方法后第一次执行。
但是我希望DbInterceptor拦截器先执行,我该怎么办?
发布于 2018-06-15 05:42:15
在MyBatis中,将首先执行后一个插件,因此我认为您只需要更改插件的配置顺序:
变出
<plugins>
<plugin interceptor="cn.common.interceptor.DbInterceptor"/>
<plugin interceptor="cn.common.interceptor.MybatisInterceptor"/>
</plugins>至
<plugins>
<plugin interceptor="cn.common.interceptor.MybatisInterceptor"/>
<plugin interceptor="cn.common.interceptor.DbInterceptor"/>
</plugins>更详细的信息可以在CSDN上找到
https://stackoverflow.com/questions/50868631
复制相似问题