spring的ProceedingJoinPoint如何串改参数?

我是这样写的
    public Object handle(ProceedingJoinPoint thisJoinPoint) throws Throwable {        Object[] objects = thisJoinPoint.getArgs();
        for (int i = 0; i < objects.length; i++) {
            Object o = objects[i];
            String json = JSONObject.toJSONString(o);
            JSONObject data = JSONObject.parseObject(json);
            data.put("sex", 20);
            objects[i] = data;
        }
        System.out.println(JSONObject.toJSONString(objects));
        Object result = thisJoinPoint.proceed(objects);
        System.out.println(result);
        return result;
    }
这样data不是原来的那个Object类型。
回答:
 JSONObject data = JSONObject.parseObject(json); data.put("sex", 20);
 objects[i] = data;
data被你改成了JSONObject 类型;
如果你想对data设置属性,建议你通过 instaceof 来判断以后进行强转后再调用setSex方法即可
例如:
if(objects[i] instanceof User){((User) objects[i]).setSex(20)
}
以上是 spring的ProceedingJoinPoint如何串改参数? 的全部内容, 来源链接: utcz.com/p/945208.html






