MyBatis 插件(拦截器)实战(自定义实现拦截器)

前言:

前面我们分析了 MyBatis 插件(拦截器)的原理,本篇分享 MyBatis 插件(拦截器)的实战。

Mybatis 相关知识传送门

初识 MyBatis 【MyBatis 核心概念】

MyBatis 源码分析–SqlSessionFactory

MyBatis 源码分析–获取SqlSession

MyBatis 源码分析-- getMapper(获取Mapper)

MyBatis 源码分析-- SQL请求执行流程( Mapper 接口方法的执行的过程)

MyBatis 源码分析-- 插件(拦截器)原理

创建自定义 MyBatis 插件(拦截器)

创建自定义 MyBatis 插件(拦截器)需要实现 org.apache.ibatis.plugin.Interceptor 接口,在类上添加 @Intercepts 注解,前文我们已经说了MyBatis 插件(拦截器)默认可以拦截的类型有四种,分别是 Executor、StatementHandler、ParameterHandler、ResultSetHandler,对自定义 插件(拦截器)必须使用 MyBatis 提供的 @Intercepts 注解来表明我们要拦截的是哪一种获几种接口,如下:

@Intercepts({
   
    @Signature(type = Executor.class, method = "query", args = {
   MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
    @Signature(type = Executor.class,method = "update",args = {
   MappedStatement.class, Object.class})
    @Signature(type = StatementHandler.class, method = "prepare", args = {
   Connection.class, Integer.class}),
    @Signature(type = ParameterHandler.class, method = "setParameters", args = {
   PreparedStatement.class}),
    @Signature(type = ResultSetHandler.<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值