Redirect
redirect重定向流程
response.sendRedirect重定向跳轉
@RequestMapping(value="/testredirect",method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView testredirect(HttpServletResponse response){
response.sendRedirect("/index");
return null;
}ViewResolver直接跳轉
@RequestMapping(value="/testredirect",method = { RequestMethod.POST, RequestMethod.GET })
public String testredirect(HttpServletResponse response){
return "redirect:/index";
} 帶參數
@RequestMapping("/testredirect")
public String testredirect(Model model, RedirectAttributes attr) {
//跳轉地址帶上test參數
attr.addFlashAttribute("test", "51gjie");
//u2參數不會跟隨在URL後面
attr.addFlashAttribute("u2", "51gjie");
return "redirect:/user/users";
}ModelAndView重定向
帶參數
總結
Last updated