1. 拦截器注解
1. mybatis自定义拦截器实现步骤:
- 实现
org.apache.ibatis.plugin.Interceptor
接口。 - 添加拦截器注解
org.apache.ibatis.plugin.Intercepts
。 - 配置文件中添加拦截器。
2. 在mybatis中可被拦截的类型有四种(按照拦截顺序):
- Executor:拦截执行器的方法。
- ParameterHandler:拦截参数的处理。
- ResultHandler:拦截结果集的处理。
- StatementHandler:拦截Sql语法构建的处理。
具体规则如下:
@Intercepts({
@Signature(type = StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),
@Signature(type = StatementHandler.class, method = "update", args = {Statement.class}),
@Signature(type = StatementHandler.class, method = "batch", args = {Statement.class})
})