mybatis些拦截器 目录 目录 简单示例 全部可被拦截的类 executor parameterHandler statementHandler 简单示例拦截Executor得query方法,打印执行sql时长 1234567891011121314151617181920212223@Intercepts({ // signature: // 1. type 类 // 2. method 方法 // 3. 参数 @Signature(type = Executor.class, method = "query", 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})})public class TestDbInterceptor implements Interceptor { @Override public Object intercept(Invocation invocation) throws Throwable { MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0]; String sqlId = mappedStatement.getId(); Object returnValue; long start = System.currentTimeMillis(); returnValue = invocation.proceed(); long end = System.currentTimeMillis(); log.info("{} -- {} ", sqlId, end - start); return returnValue; }} 全部可被拦截的类executor主从库查询的拦截器进行主从切换,aop也可以,但是得拦截方法不如此方法更友好 parameterHandlerstatementHandler1234567891011121314151617181920212223// 分页插件拦截此方法Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException;void parameterize(Statement statement) throws SQLException;void batch(Statement statement) throws SQLException;int update(Statement statement) throws SQLException;<E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException;<E> Cursor<E> queryCursor(Statement statement) throws SQLException;BoundSql getBoundSql();ParameterHandler getParameterHandler();