RequestContextHolder
当我们需要在service层获取request和response时,我们可以在RequestContextHolder中获取。
使用方法:
RequestAttributes requsetAttributes = RequestContextHolder.currentRequestAttributes();
//RequestAttributes requsetAttributes = RequestContextHolder.getRequestAttributes();
String str = (String) requsetAttributes.getAttribute("name", RequestAttributes.SCOPE_SESSION);
HttpServletRequest request = ((ServletRequestAttributes) requsetAttributes).getRequest();
HttpServletResponse reponse = ((ServletRequestAttributes) requsetAttributes).getResponse();