mybatis若想实现自定义拦截器,需要实现Interceptor接口,对象首先会执行plugin(Object target)方法,根据类上的@Intercepts注解决定是否拦截。若需要拦截,则调用intercept(Invocation invocation)方法。
1. 准备工作
需要拦截的sql:
需要拦截的Mapper对象:
invocation对象:
invocation对象
可以看到invocation中的args参数,就是@Intercepts中的args参数。
2. mappedStatement对象
1. invocation对象如何获取mappedStatement对象:
一个mappedStatement对象对应Mapper配置文件中的一个select/update/insert/delete节点,主要描述的是一条sql语句。
MappedStatement.png
2. MappedStatement对象详解:
其中真正表示SQL的