apsectj常用方法

1、获取参数名称 和 值

@Pointcut("execution(*  com.business..*.*(..))")
    public void point(){

    }

@Around(value = "point()")
public Object invoke(ProceedingJoinPoint joinPoint) {

       
        //1.这里获取到所有的参数值的数组
        Object[] args = joinPoint.getArgs();
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        //2.获取参数名称
        String[] parameterNames = methodSignature.getParameterNames();
        try {
            //3.通过你需要获取的参数名称的下标获取到对应的值
            String userName= ArrayUtils.indexOf(parameterNames, "userName");
           
            return joinPoint.proceed();
        } catch (Throwable throwable) {

            throwable.printStackTrace();
           
        }
    }

 

你可能感兴趣的:(Aspectj)