加类注解:@SessionAttributes("graduateProject")
如下所示:
@SessionAttributes("graduateProject")
public class ProjectController {
......
@RequestMapping(value = "/updateGraduateProject", method = RequestMethod.POST)
public ModelAndView update(GraduateProject graduateProject,SessionStatus status) {
graduateProjectService.updateGraduateProject(graduateProject);
//将graduateProject从session中清除掉
status.setComplete();
ModelAndView returnModelAndView = this.list();
if (logger.isDebugEnabled()) {
logger.debug("update(GraduateProject, SessionStatus) - end");
}
return returnModelAndView;
}
修改返回list后,刷新,则出现:
Session attribute 'graduateProject' required - not found in session
status.setComplete();注释掉,则不再出现。但不能总让它呆在session里面吧!
原因是:
错误地以forward方式返回视图
//如果不使用redirect的话,当前的地址仍然为"/bysj/project/updateGraduateProject.html"。
//如果刷新的话,会重新调用本方法,而status.setComplete清除了session,所以会出现
//"Session attribute 'graduateProject' required - not found in session"
// return this.list().getViewName();转发模式,目标地址不变
return "redirect:/project/listGraduateProjects.html";//重向模式