@Intercepts({
@Signature(
method = "query",
type = Executor.class,
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
),
@Signature(
type = Executor.class,
method = "query",
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
@Signature(
method = "update",
type = Executor.class,
args = {MappedStatement.class, Object.class}
)
})
public class MybatisMonitorInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object target = invocation.getTarget();
Object result = null;
final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
if (target instanceof Executor) {
try {
result = invocation.proceed();
} catch (Exception e) {
return null;
}
if (Objects.isNull(result)) {
return null;
}
}
return result;
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
}
【烦人的mybatis】Mybatis自定义拦截器
最新推荐文章于 2025-03-27 13:53:43 发布