Spring切面编程获取HttpServletRequest和HttpServletResponse

在切面编程的时候,HttpServletRequest和HttpServletResponse是不属于传入的参数范围的。

这个时候怎么获取request和response参数呢?

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

我们可以通过上下文容器获取到request和response

你可能感兴趣的:(Spring切面编程获取HttpServletRequest和HttpServletResponse)