如何在joinpoint.getArgs()中获取方法参数值? [英] How to get method argument value in joinpoint.getArgs()?

查看:104
本文介绍了如何在joinpoint.getArgs()中获取方法参数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    String type = "";
if("searchClientContactDetails".equalsIgnoreCase(methodName) || "getClientAndVendorOrgDeatilsById".equalsIgnoreCase(methodName) 
                || "saveVenodrContact".equalsIgnoreCase(methodName) || "getSpocAndOwnerDetailsById".equalsIgnoreCase(methodName)
                || "terminateSpoc".equalsIgnoreCase(methodName)){
    Object[] args = joinPoint.getArgs();
            Object arg=args[0];
            Class c=arg.getClass();
            type=(String)c.getMethod("getResponderType").invoke(arg);
}

从上面的代码中,如果我的 getResponderType 值在 args[0] 中,那么我得到了所需的值,如果我的值出现在 args[1] 或 args[2] 中怎么办(对多种方法使用相同的值).在我的代码中,我将在少数方法的第一个参数中获取getResponderType"值,而在其他方法中,我将在第二个或第三个参数中获取它.

From the above code if my getResponderType value is in the args[0] then i am getting the required value , what if my value is present in args[1] or args[2] (using the same for multiple methods). In my code i will get the "getResponderType" value in first argument for few methods and in another methods i will be getting it in second or third argument.

推荐答案

您可以遍历 args 以查找方法 getResponderType.一旦你找到你要找的东西,你就可以打破了.

You can iterate over the args looking for the method getResponderType. Once you find what you are looking for, you can break.

String type = "";
Object[] args = joinPoint.getArgs();
for (Object arg : args) {
    Class clazz = arg.getClass();
    try {
        Method mthd = arg.getClass().getMethod("getResponderType");
        if (mthd != null) {
            type = (String) clazz.getMethod(
                            "getResponderType").invoke(arg);
            break;
        }
    } catch (Exception e) {
        //do nothing
    }
}

这篇关于如何在joinpoint.getArgs()中获取方法参数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆