掘金 后端 ( ) • 2024-05-17 10:12

获取当前request

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

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

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

https://zhhll.icu/2021/框架/springmvc/基础/9.spring获取当前request/

本文由mdnice多平台发布