可携带数据跳转

1. 新增可携带数据跳转的功能
2. 完善README
3. 修改示例
This commit is contained in:
yangsuiyu
2020-04-07 21:53:25 +08:00
parent 119436dc3b
commit 7c807d4b39
39 changed files with 1097 additions and 277 deletions

View File

@@ -28,7 +28,6 @@ public class FXControllerProxy implements MethodInterceptor {
public Object getInstance(FXBaseController target) {
this.target = target;
// System.out.println(target.toString());
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(this.target.getClass());
enhancer.setCallback(this);

View File

@@ -19,6 +19,11 @@ public class FXEntityProxy implements MethodInterceptor {
Object target;
private Map<String, FXFieldWrapper> fxFieldWrapperMap;
/**
* @param target
* @return
* @Desciption 通过getInstance获取代理对象
*/
public Object getInstance(Object target) {
this.target = target;
Enhancer enhancer = new Enhancer();
@@ -30,51 +35,53 @@ public class FXEntityProxy implements MethodInterceptor {
/**
* intercept get and set method and
*
* @param o
* @param method
* @param objects
* @param methodProxy
* @param proxy cglib生成的代理对象
* @param method 被代理对象的方法
* @param args 拦截的方法的入参
* @param methodProxy 拦截方法的代理方法
* @return
* @throws Throwable
* @Descripton 拦截getter, setter, del, cls, add方法
*/
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects); //获取该方法运行后的结果
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object revokeResult = methodProxy.invokeSuper(proxy, args); //获取该方法运行后的结果
String methodName = method.getName();
String fieldName = null;
if (methodName.length() >= 3) {
fieldName = StringUtils.toInstanceName(methodName.substring(3)); // 该method有可能是getter和setter方法进行处理
} else {
return o1;
return revokeResult;
}
FXFieldWrapper fxFieldWrapper = fxFieldWrapperMap.get(fieldName);
Property property = getPropertyByFieldName(fieldName);
if (fxFieldWrapper == null || property == null) {
return o1;
if (fxFieldWrapper == null || property == null) { //非属性的getter或setter
return revokeResult;
}
Class type = fxFieldWrapper.getType();
if (methodName.startsWith("set")) {
if(Boolean.class.equals(type) || boolean.class.equals(type)){
((SimpleBooleanProperty)property).set((Boolean)objects[0]);
}else if(Double.class.equals(type)||double.class.equals(type)){
((SimpleDoubleProperty)property).set((Double)objects[0]);
}else if (Float.class.equals(type) || float.class.equals(type)){
((SimpleFloatProperty)property).set((Float) objects[0]);
}else if(Integer.class.equals(type) || int.class.equals(type)){
((SimpleIntegerProperty)property).set((Integer) objects[0]);
}else if(Long.class.equals(type) ||long.class.equals(type)){
((SimpleLongProperty)property).set((Long)objects[0]);
}else if(String.class.equals(type)){
((SimpleStringProperty)property).set((String)objects[0]);
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
((SimpleBooleanProperty) property).set((Boolean) args[0]);
} else if (Double.class.equals(type) || double.class.equals(type)) {
((SimpleDoubleProperty) property).set((Double) args[0]);
} else if (Float.class.equals(type) || float.class.equals(type)) {
((SimpleFloatProperty) property).set((Float) args[0]);
} else if (Integer.class.equals(type) || int.class.equals(type)) {
((SimpleIntegerProperty) property).set((Integer) args[0]);
} else if (Long.class.equals(type) || long.class.equals(type)) {
((SimpleLongProperty) property).set((Long) args[0]);
} else if (String.class.equals(type)) {
((SimpleStringProperty) property).set((String) args[0]);
}
}else if (methodName.startsWith("add")){
((SimpleListProperty)(property)).add(objects[0]);
}else if(methodName.startsWith("del")){
((SimpleListProperty)(property)).remove(objects[0]);
}else if(methodName.startsWith("cls")){
((SimpleListProperty)(property)).clear();
} else if (methodName.startsWith("add")) {
((SimpleListProperty) (property)).add(args[0]);
} else if (methodName.startsWith("del")) {
((SimpleListProperty) (property)).remove(args[0]);
} else if (methodName.startsWith("cls")) {
((SimpleListProperty) (property)).clear();
}
return o1;
return revokeResult;
}
public Object getTarget() {
@@ -92,11 +99,11 @@ public class FXEntityProxy implements MethodInterceptor {
return fxFieldWrapperMap.get(name).getProperty();
}
public Map<String, FXFieldWrapper> getFxFieldWrapperMap() {
public Map<String, FXFieldWrapper> getFXFieldWrapperMap() {
return fxFieldWrapperMap;
}
public void setFxFieldWrapperMap(Map<String, FXFieldWrapper> fxFieldWrapperMap) {
public void setFXFieldWrapperMap(Map<String, FXFieldWrapper> fxFieldWrapperMap) {
this.fxFieldWrapperMap = fxFieldWrapperMap;
}
}