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

@Pointcut("execution(* com.sweet.example.service.*.list*(..))")
public void pointCut() {
}
@Before(value = "pointCut()")
private Map<String, Object> getFieldsName(JoinPoint joinPoint){
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
    //获取当前切点方法对象
    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<String, Object> map = new HashMap<String, Object>();
    //参数名称
    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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章