说明:
本文以环绕切面配合反射、注解为示例
- @Around(value = "cutMethods() && withAnnotationMethods()")
- public Object around(ProceedingJoinPoint point) throws Throwable {
- long startTime = System.currentTimeMillis();
-
- //通过请求上下文持有者,获取 Servlet 容器对象
- ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
- //通过 Servlet 容器对象获取 request 请求对象
- HttpServletRequest request = attributes.getRequest();
-
- MethodSignature methodSignature = (MethodSignature) point.getSignature();
- Method method = methodSignature.getMethod();
- BusinessLock lockAnnotation = method.getAnnotation(BusinessLock.class);
-
- //获取所有参数的类型和名称
- Parameter[] parameters = method.getParameters();
-
- //获取所有参数的值
- Object[] args = point.getArgs();
-
- //获取全部参数信息数组、以及每个参数的全部注解信息数组
- Annotation[][] para