1、在filter中获取Request
- HttpServletRequest req = RequestContext.getCurrentContext().getRequest();
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
- req = ((ServletRequestAttributes) requestAttributes).getRequest();
2、在controller和service中获取Request
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
- req = ((ServletRequestAttributes) requestAttributes).getRequest();
获取request的两种方式
原文:https://www.cnblogs.com/yulongzhang/p/15222533.html