在我的请求中,我有一个参数名称"accessToken",如何从ProceedingJoinPoint获取请求参数值?
public Object handleAccessToken(ProceedingJoinPoint joinPoint) throws Throwable {
final Signature signature = joinPoint.getStaticPart().getSignature();
if (signature instanceof MethodSignature) {
final MethodSignature ms = (MethodSignature) signature;
String[] params = ms.getParameterNames();
for (String param : params) {
System.out.println(param);
// here how do i get parameter value using param ?
}
}
}
Run Code Online (Sandbox Code Playgroud)
通话方式:
public MyResponse saveUser(
@RequestParam("accessToken") String accessToken,
@RequestBody final UserDto userDto
) {
// code
}
Run Code Online (Sandbox Code Playgroud)
我想在AOP中获取此访问令牌.
提前致谢.
在以下情况下,我需要使用与方法匹配的切入点创建方面:
方面类看起来像这样
@Pointcut("execution(@MyAnnotationForMethod * *(..,@aspects.MyAnnotationForParam Object, ..)) && args(obj)")
void myPointcut(JoinPoint thisJoinPoint, Object obj) {
}
@Before("myPointcut(thisJoinPoint , obj)")
public void doStuffOnParam(JoinPoint thisJoinPoint, Object obj) {
LOGGER.info("doStuffOnParam :"+obj);
}
Run Code Online (Sandbox Code Playgroud)
注释方法
@MyAnnotationForMethod
public string theMethod(String a, @MyAnnotationForParam @OtherAnnotation Object obj, Object b){
LOGGER.info(a+obj+b);
}
Run Code Online (Sandbox Code Playgroud)
用eclipse - >警告:关于poincut:
Multiple markers at this line
- no match for this type name: MyAnnotationForMethod [Xlint:invalidAbsoluteTypeName]
- no match for this type name: aspects.MyAnnotationForParam On the before : advice defined in xxx.xxx.xxx.xxx.MyAspect has not …Run Code Online (Sandbox Code Playgroud)