jinpengyong
2023-11-10 c64ca12b8679d73fc7f8109f0e08fa8c74352164
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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) {
 
    }
 
}