@Controller
@RequestMapping(value = "/trip")
public class BusController {
private BusDao bdao;
@Inject
public BusController(BusDao bdao) {
this.bdao = bdao;
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@ModelAttribute Bus bus) {
return "redirect:/ordersummary";
}
创建运行后,我试图重定向到另一个名为“ordersummary.jsp”的JSP,我似乎无法弄清楚如何做到这一点。我是否需要另一个带有重定向的控件的控制器?
答案 0 :(得分:0)
您的代码是正确的,但是当您执行重定向时,您需要配置一个控制器来处理重定向将执行的get请求。
因此您的控制器可能如下所示:
@Controller
@RequestMapping(value = "/trip")
public class BusController {
private BusDao bdao;
@Inject
public BusController(BusDao bdao) {
this.bdao = bdao;
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@ModelAttribute Bus bus) {
return "redirect:/ordersummary";
}
@RequestMapping(value = "/ordersummary", method = RequestMethod.POST)
public String redirectHAndler(....) {
...
return "yourView";
}
}
我希望它可以帮到你