其他分享
首页 > 其他分享> > 在Springboot上下文中获取HttpServletRequest和HttpServletResponse

在Springboot上下文中获取HttpServletRequest和HttpServletResponse

作者:互联网


HttpServletRequest request =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response =((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();


一般使用

HttpServletRequest request =((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();

HttpServletResponse response =((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getResponse();

标签:HttpServletRequest,Springboot,RequestContextHolder,getRequestAttributes,ServletR
来源: https://blog.csdn.net/weixin_43702146/article/details/121266370