0
点赞
收藏
分享

微信扫一扫

spring boot配置Aop获取controller里的request中的参数以及其返回值

@Aspect
  @Configuration
  public class ApiLogAop {
  @Pointcut("execution(*
  com.user.api.controller.*.*(..))")
  public void excuteService(){
  }
  @Around("excuteService()")
  public Object doAround(ProceedingJoinPoint
  point) throws Throwable{
  RequestAttributes ra=RequestContextHolder.getRequestAttributes();
  ServletRequestAttributes
  sra=(ServletRequestAttributes )ra;
  HttpServletRequest request=sra.getRequest();
  String url=request.getRequestURL().toString();
  String method=request.getMethod();
  String uri=request.getRequestURI();
  String queryString=request.getQueryString();
  System.out.println("萩箔蝕兵, 光倖歌方, url: "+url+",
  method: "+method+", uri:"+uri+", params:"+queryString);
  String simpleName=point.getTarget().getClass().getSimpleName();
  String methodName=point.getSignature().getName();
  MethodSignature methodSignature=(MethodSignature)
  point.getSignature();
  String[] parameterNames=methodSignature.getParameterNames();
  Object[] param=point.getArgs();
  StringBuffer str=new StringBuffer();
  if(parameterNames!=null){
  for(int i=0;i
  str.append("歌方兆:").append(parameterNames[i]).append("=").append(param[i]);
  }
  }
  System.out.println(str.toString());
  Object result=point.proceed();
  return result;
  }
  }

举报

相关推荐

0 条评论