package com.moral.api.config.mybatis;
|
|
import org.apache.ibatis.executor.statement.StatementHandler;
|
import org.apache.ibatis.mapping.BoundSql;
|
import org.apache.ibatis.mapping.MappedStatement;
|
import org.apache.ibatis.plugin.*;
|
import org.apache.ibatis.reflection.DefaultReflectorFactory;
|
import org.apache.ibatis.reflection.MetaObject;
|
import org.apache.ibatis.reflection.SystemMetaObject;
|
import java.sql.Connection;
|
import java.util.Properties;
|
|
import static javax.xml.bind.JAXBIntrospector.getValue;
|
|
|
/**
|
* @ClassName MybatisIntercept
|
* @Description TODO
|
* @Author 陈凯裕
|
* @Date 2021/9/17 10:57
|
* @Version TODO
|
**/
|
//@Component
|
/*@Intercepts({
|
//type指定代理的是那个对象,method指定代理Executor中的那个方法,args指定Executor中的query方法都有哪些参数对象
|
//由于Executor中有两个query,因此需要两个@Signature
|
@Signature(type = Executor.class,method = "query",args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
|
@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class })//需要代理的对象和方法
|
})*/
|
|
@Intercepts({
|
//type指定代理的是那个对象,method指定代理Executor中的那个方法,args指定Executor中的query方法都有哪些参数对象
|
//由于Executor中有两个query,因此需要两个@Signature
|
@Signature(method = "prepare", type = StatementHandler.class, args = {Connection.class,Integer.class})
|
})
|
public class MybatisIntercept implements Interceptor {
|
|
@Override
|
public Object intercept(Invocation invocation) throws Throwable {
|
System.out.println(11);
|
return null;
|
}
|
|
@Override
|
public Object plugin(Object target) {
|
Object wrap = Plugin.wrap(target, this);
|
return wrap;
|
}
|
|
@Override
|
public void setProperties(Properties properties) {
|
|
}
|
|
}
|