spring获取当前request

142 阅读1分钟

获取当前request

有时候需要在处理业务的时候用到request对象,可以使用该方法获取

HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();

使用RequestContextHolder.currentRequestAttributes()获取的RequestAttributes对象是线程局部变量(ThreadLocal),request对象也是线程局部变量

zhhll.com.cn/2021/框架/spr…