实现FX-PLus和Spring结合的Demo

This commit is contained in:
billkiller
2019-07-07 12:21:30 +08:00
parent bb53425b43
commit 7ce75c9206
35 changed files with 1326 additions and 497 deletions

View File

@@ -8,6 +8,7 @@ import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
@@ -23,18 +24,23 @@ public class FXControllerProxy implements MethodInterceptor {
FXBaseController target;
public Object getInstance(FXBaseController target) {
this.target = target;
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(this.target.getClass());
enhancer.setCallback(this);
return enhancer.create();
Object proxy = enhancer.create();
inject(target, proxy);
return proxy;
}
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Annotation []annotations = method.getDeclaredAnnotations();
// System.out.println("name" +target.getName());
for(Annotation annotation : annotations){
if(FXSender.class.equals(annotation.annotationType())){
FXSender fxSender = (FXSender)annotation;
@@ -44,10 +50,24 @@ public class FXControllerProxy implements MethodInterceptor {
}else{
name += fxSender.name();
}
System.out.println("method" + name);
MessageQueue.getInstance().sendMsg(name,o1);
}
}
return o1;
}
private void inject(Object target,Object proxy){
Field[] fields = target.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
try {
Object filedValue = field.get(target);
System.out.println(filedValue);
field.set(proxy,filedValue);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -41,8 +41,8 @@ public class FXEntityProxy implements MethodInterceptor {
*/
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Object o1 = methodProxy.invokeSuper(o, objects);
String methodName = method.getName();
String fieldName = null;
if (methodName.length() >= 3) {
@@ -55,7 +55,7 @@ public class FXEntityProxy implements MethodInterceptor {
if(fxFieldPropertyMapping == null || property == null){
return o1;
}
System.out.println("??? <--->");
Class type = fxFieldPropertyMapping.getType();
if (methodName.startsWith("set")) {
if(Boolean.class.equals(type)){