springMVC中,为了方便随时获取当前的request对象,可以通过RequestContextHolder的静态方法getRequestAttributes()获取Request相关的变量,如request, response等。
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes)ra).getRequest();
通过这种方式,就不需要在接收或传递参数的时候通过定义HttpRequest或HttpResponse来获取参数了。
最后
以上就是懵懂御姐最近收集整理的关于通过RequestContextHolder获取HttpServletRequest的全部内容,更多相关通过RequestContextHolder获取HttpServletRequest内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复