RequestContextHolder
RequestContextHolder
在Spring编程中经常使用到,可以用来获取请求的相关信息;该类可以暴露线程绑定的web请求属性RequestAttributes
,项目中常用的用法:
- RequestAttributes RequestContextHolder.getRequestAttributes(); 在servlet环境下返回的是ServletRequsetAttributes;
ServletRequestAttributes
ServletRequsetAttributes
,项目中常用的用法:
- HttpServletRequest ServletRequestAttributes.getRequest();
- HttpSession ServletRequestAttributes.getSession(boolean allowCreate);
结合 request.getHeaderNames();request.getQuestString();request.getHeader(String headerName)
AOP中常用的JoinPoint
JoinPoint常见的使用方法:
- String JoinPoint.getArgs();
- String JoinPoint.getSignature().getDeclaringTypeName();返回声明的类名
- String JoinPoint.getSignature().getName();返回方法名
- Signature JoinPoint.getSignature(); 常用的JoinPoint是MethodInvocationProceedingJoinPoint类,该方法获取的对象为MethodSignature;
MethodSingagture.getMethod().getAnnotation(clsss);获取方法上的注解