转发、重定向到其它业务方法
@org.springframework.stereotype.Controller
@RequestMapping("/userController")public classUserController{
@RequestMapping("/handler1")public String handler1() throwsIOException {//转发给handler2处理
return "forward:handler2";
}
@RequestMapping("/handler2")public void handler2(HttpServletResponse response) throwsIOException {//......
}
}
返回String,在里面加上关键字:forward(转发),redirect(重定向)。
(1)如果是转发、重定向到本controller的其它业务方法:
可以写全路径
return "forward:/userController/handler2";
也可以只写子路径,但不要子路径开头的斜杠
不管handler2()是标注为@RequestMapping("/handler2"),还是标注为@RequestMapping("handler2"),都只能这样:
return "forward:handler2";
(2)如果是转发、重定向到其它controller的业务方法,只能写全路径。
转发、重定向