Skip to content

Instantly share code, notes, and snippets.

@warriorg
Created December 23, 2019 02:36
Show Gist options
  • Save warriorg/528f974d3847bcb763bffe18540edb03 to your computer and use it in GitHub Desktop.
Save warriorg/528f974d3847bcb763bffe18540edb03 to your computer and use it in GitHub Desktop.
通过spring,在项目的任意位置获取当前Request
public static HttpServletRequest getRequest(){
ServletRequestAttributes ra= (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = ra.getRequest();
return request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment