package com.monkeylessey.framework.plugins;
|
|
import com.monkeylessey.framework.config.MybatisPlusConfig;
|
import org.apache.ibatis.executor.Executor;
|
import org.apache.ibatis.mapping.MappedStatement;
|
import org.apache.ibatis.plugin.Interceptor;
|
import org.apache.ibatis.plugin.Intercepts;
|
import org.apache.ibatis.plugin.Invocation;
|
import org.apache.ibatis.plugin.Signature;
|
import org.apache.ibatis.session.ResultHandler;
|
import org.apache.ibatis.session.RowBounds;
|
|
/**
|
* mybatis插件demo
|
* 针对自己写的mqpper方法才会走这个插件,plus内置方法要想使用插件,只能用plus的插件
|
* @see MybatisPlusPluginDemo plus的插件写法
|
* @see MybatisPlusConfig 如何配置 line 46 & 56
|
*
|
* @author xp
|
* @data 2023/11/14
|
*/
|
@Intercepts(
|
@Signature(
|
type = Executor.class,
|
method = "query",
|
args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
|
)
|
)
|
public class MybatisPluginDemo implements Interceptor {
|
|
@Override
|
public Object intercept(Invocation invocation) throws Throwable {
|
// 执行之前
|
System.out.println("mybatis插件执行之前");
|
// 执行sql
|
Object result = invocation.proceed();
|
// 执行之后
|
System.out.println("mybatis插件执行之后");
|
return result;
|
}
|
}
|