mybatis插件(拦截器)

2021/11/20 mybatis 共 494 字,约 2 分钟
闷骚的程序员

1. 什么是mybatis的Plugin?

mybatis提供了一种插件(Plugin)机制,虽说叫插件,但实际上就是拦截器。

mybatis允许你在已映射语句的执行过程中的某一点进行拦截,从而插入自定义的逻辑。
默认情况下,mybatis允许使用插件来拦截的对象(当然包括对象中的某些方法)如下:

1.拦截执行器 Executor 对象,可以拦截下面的方法:
update, query, flushStatements, commit, rollback, getTransaction, close, isClosed
2.参数控制器 ParameterHandler 对象:
getParameterObject, setParameters
3.结果控制器 ResultSetHandler对象:
handleResultSets, handleOutputParameters
4.SQL语句构建控制器 StatementHandler 对象:
prepare, parameterize, batch, update, query

通过mybatis内置提供的拦截器接口,可以拦截对应的mybatis对象,从而更改mybatis的执行逻辑。

文档信息

Search

    Table of Contents