AOP JoinPoint 获取方法属性 参数名称值Map对象

@Pointcut("execution(* com.sweet.example.service.*.list*(..))")
public void pointCut() {
}
@Before(value = "pointCut()")
private Map getFieldsName(JoinPoint joinPoint){
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    //方法所属类的类名
     String ClassName =  methodSignature.getDeclaringTypeName();
    //获取当前切点方法对象
    Method method = methodSignature.getMethod();
    //打印方法名
    System.out.println(method.getName());
    
    //方法参数的类型
    Class[] parameterTypes = method.getParameterTypes();
    for (Class clas : parameterTypes) {
        String parameterName = clas.getName();
        System.out.println("参数类型:" + parameterName);

    }



    Map map = new HashMap();
    //参数名称
    String[] names=((MethodSignature) joinPoint.getSignature()).getParameterNames();
    //参数值
    Object[] objects=joinPoint.getArgs();
    for (int i = 0; i < names.length; i++) {
        map.put(names[i], objects[i]);
    }
    return map;
}

你可能感兴趣的:(Java)