我想检索 MethodInterceptor 类上方法的参数名称。
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
Class<?> declaringClass = method.getDeclaringClass();
Logger logger = LoggerFactory.getLogger(declaringClass);
//here some treatment
return invocation.proceed();
}
而且我只是找不到如何使用 MethodInvocation 实例检索方法参数的名称。我不确定这是否可能..
最佳答案
你不能。 Java 不会在运行时保留参数名称,因此,拦截器(或反射 api)无法获取它。 解决此问题的一种方法是将您的参数包装在一个类中,并具有名称与您的参数名称相对应的字段。
关于java - 如何获取MethodInterceptor中方法的参数名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6218394/