标签:
经常需要在spring的controller之间跳转request,自然想到servlet的forward和redirect方法,还好,spring也提供了类似方法。
@RequestMapping(value="/main", method={RequestMethod.GET, RequestMethod.POST}) public String showBlogMain(Model model){ setTopLevelChannels(model); List<Blog> blogs = blogService.listBlog(); model.addAttribute("blogs", blogs); return "blog/blog_main"; }
@RequestMapping(value="/update",method=RequestMethod.POST) public String updateBlog( @ModelAttribute(value="blog") Blog blog, BindingResult result){ blogService.updateBlog(blog);// //return new ModelAndView("forward:/blog/main"); return "forward:/blog/main"; //return "redirect:/blog/main"; }
注意:上面是从GET请求跳到了POST请求。
标签:
原文地址:http://www.cnblogs.com/xiuquan/p/4871072.html