1.在controller层面获取request,直接在对应的方法中传递HttpServletRequest对象。
2.在service层面获取request,使用RequestContextHolder类
public HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
1.在controller层面获取request,直接在对应的方法中传递HttpServletRequest对象。
2.在service层面获取request,使用RequestContextHolder类
public HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
本文标题:springmvc中获取request对象
本文链接:https://www.haomeiwen.com/subject/baebrqtx.html
网友评论