我需要API调用的请求和响应,我正在获取所需的所有请求参数,但响应始终为null,我需要HttpServletResponse响应来获取请求主体,我该怎么办?
@Around("@annotation(Loggable)")
public Object loggable(ProceedingJoinPoint joinPoint) throws Throwable {
Object proceed = joinPoint.proceed();
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
ServletWebRequest servletWebRequest = new ServletWebRequest(request);
HttpServletResponse response = servletWebRequest.getResponse();
}
答案 0 :(得分:0)
假设Loggable是在控制器方法中定义和使用的自定义注释,则以上代码块中定义的proceed
变量应具有API的响应。