springMVC两个Controller传递参数
2020-08-26 本文已影响0人
木羽
/**
*ControllerA的代码
**/
@RequestMapping("addComment")
public String addComment(Comment comment,Model model){
if(cs.addComment(comment)){
model.addAttribute("id",comment.getCommentBookId());
//一定要加重定向
return "redirect:getBookDetail.action";
}
return "fail.jsp";
}
/**
*ControllerB的代码
**/
@RequestMapping("getBookDetail")
public String getBookDetail(Model model,@RequestParam(value="id",required=true)int id){
Book book = bs.getBookById(id);
model.addAttribute("book",book);
return "bookDetail.jsp";
}