请求转发
两种方式
第一种:返回一个ModeAndView
@RequestMapping("/test1.action")
public ModelAndView test1() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("/resoult.jsp");
return modelAndView;
}
第二种:直接返回一个字符转
@RequestMapping("/test2.action")
public String test2() {
System.out.println("来到了测试2");
return "resoult.jsp";
}
重定向
在返回的return那里加上一个redirect:即可
@RequestMapping("/test1.action")
public ModelAndView test1() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("name","dage");
modelAndView.setViewName("redirect:/resoult.jsp");
return modelAndView;
}
@RequestMapping("/test2.action")
public String test2() {
System.out.println("来到了测试2");
return "redirect:/resoult.jsp";
}
控制器之间的跳转
直接返回控制器的映射名即可
@RequestMapping("/test1.action")
public ModelAndView test1() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("name","dage");
modelAndView.setViewName("/test2.action");
return modelAndView;
}
@RequestMapping("/test2.action")
public String test2() {
System.out.println("来到了测试2");
return "/resoult.jsp";
}