不带参数
@RequestMapping(value="/restredirect",method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView restredirect(String userName){ ModelAndView model = new ModelAndView("redirect:/main/index"); return model; }
带参数
@RequestMapping(value="/toredirect",method = { RequestMethod.POST, RequestMethod.GET }) public ModelAndView toredirect(String userName){ ModelAndView model = new ModelAndView("/main/index"); model.addObject("userName", userName); //把userName参数带入到controller的RedirectAttributes return model; }
这篇文档对您是否有帮助?