forked from mood321/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefautoDao.java
More file actions
31 lines (23 loc) · 840 Bytes
/
Copy pathDefautoDao.java
File metadata and controls
31 lines (23 loc) · 840 Bytes
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
package proxy.CGlib;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;
public class DefautoDao implements MethodInterceptor {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
System.out.println("Befor");
methodProxy.invokeSuper(o,objects);
System.out.println("after");
return o;
}
public static void main(String[] args) {
//
DefautoDao daoProxy = new DefautoDao();
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(CglibInterface.class);
enhancer.setCallback(daoProxy);
CglibInterface o = (CglibInterface)enhancer.create();
o.select();
}
}