首页 > 代码库 > 获得request对象

获得request对象

  @RequestMapping("/navQueryMap")
    public String navQueryMap(@RequestParam(value="http://www.mamicode.com/queryOrigin",required=false) String queryOrigin,
                              @RequestParam(value="queryDestination",required=false) String queryDestination,
                              @RequestParam(value="queryStartTime",required=false) String queryStartTime,
                              @RequestParam(value="queryEndTime",required=false) String queryEndTime) {

        /*在一个普通类中获得 HttpServletRequest 对象*/
        HttpServletRequest request =  ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

        HttpSession session = request.getSession();
        session.setAttribute("queryOrigin", queryOrigin);
        session.setAttribute("queryDestination", queryDestination);
        session.setAttribute("queryStartTime", queryStartTime);
        session.setAttribute("queryEndTime", queryEndTime);

        return "navQueryMap";
    }

 

获得request对象