本文共 1738 字,大约阅读时间需要 5 分钟。
@Controller @RequestMapping(value = "/redirect") public class Test { //进入路径/SpringMVCDemo/redirect/test1 //重定向路径/SpringMVCDemo/redirect/index @RequestMapping("/test1") public ModelAndView test1(ModelAndView view) { view.setViewName("redirect:index"); return view; } //进入路径/SpringMVCDemo/redirect/test2。 //重定向路径/SpringMVCDemo/redirect/login @RequestMapping("/test2") public ModelAndView test2(ModelAndView view) { view.setViewName("redirect:login"); return view; } //进入路径/SpringMVCDemo/redirect/test3。 //重定向路径/SpringMVCDemo/index。 @RequestMapping("/test3") public ModelAndView test3(ModelAndView view) { view.setViewName("redirect:/index"); return view; } //进入路径/SpringMVCDemo/redirect/test4。 //重定向路径/index。 @RequestMapping("/test4") public ModelAndView test4(ModelAndView view) { view.setView(new RedirectView("/index", false)); return view; } //进入路径/SpringMVCDemo/redirect/test5。 //重定向路径/SpringMVCDemo/redirect/index。 @RequestMapping("/test5") public ModelAndView test5(ModelAndView view) { view.setView(new RedirectView("index", false)); return view; } //进入路径/SpringMVCDemo/redirect/test6/1。 //重定向路径/SpringMVCDemo/index1?test=test。 @RequestMapping("/test6/{id}") public ModelAndView test6(ModelAndView view, @PathVariable("id") int id) { view.setViewName("redirect:/index{id}"); view.addObject("test", "test"); return view; } //进入路径/SpringMVCDemo/redirect/test7/1 //重定向路径/SpringMVCDemo/index{id}。 @RequestMapping("/test7/{id}") public ModelAndView test7(ModelAndView view, @PathVariable("id") int id) { RedirectView redirectView = new RedirectView("/index{id}"); redirectView.setExpandUriTemplateVariables(false); redirectView.setExposeModelAttributes(false); view.setView(redirectView); view.addObject("test", "test"); return view; } }转载地址:http://xpjqi.baihongyu.com/