在spring的业务层获取request,response

1.直接通过controller层获取到传输到业务层
2.SpringMVC提供的RequestContextHolder可以直接获取
代码:
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
// RequestContextHolder.getRequestAttributes();
//从session里面获取对应的值
String str = (String) requestAttributes.getAttribute("name",RequestAttributes.SCOPE_SESSION);

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

猜你喜欢

转载自www.cnblogs.com/shanshen/p/9769714.html
今日推荐