AOP获取切入点方法形参的名称和对应的值

 /**
     * @Author Xiaotianyu
     * @Description 形参转map  key为名字,value为值
     **/
    private HashMap paramToMap(ProceedingJoinPoint joinPoint) {

        HashMap map = new HashMap<>();

        //获取参数对象
        Object[] args = joinPoint.getArgs();

        //参数列表
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        String[] parameterNames = methodSignature.getParameterNames();

        int index = 0;
        for(String str : parameterNames) {
            map.put(str,args[index++]);
        }

        return map;
    }

 

你可能感兴趣的:(java基础)