springboot获取HttpServletRequest和HttpServletResponse

@GetMapping(value = "")
public String center() {
    ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = servletRequestAttributes.getRequest();
    HttpServletResponse response = servletRequestAttributes.getResponse();
    //...
}
@GetMapping(value = "")
public String center(HttpServletRequest request,HttpServletResponse response) {
    //...
}
@Autowired
private HttpServletRequest request;
 
@Autowired
private HttpServletResponse response;

 

posted @ 2021-03-30 09:15  24601  阅读(547)  评论(0编辑  收藏  举报