When do @SessionAttributes in SpringMVC get removed? (With code sample)

て烟熏妆下的殇ゞ 提交于 2019-12-03 05:46:49

You indicate completion of the conversation by calling

SessionStatus.setComplete

public void post(...., SessionStatus status) {
  status.setComplete();
}

That said, I don't see why you should be loosing one model attribute and not the other.

Have you tried doing something like:

@ModelAttribute("object1")
public Object object1() { return new Object(); }

@ModelAttribute("object2")
public Object object2() { return new Object(); }

And see how that compares to putting the attributes in the model by hand.

You can remove single session level ModelAttribute like this:

Given ModelMap model, HttpSession session and you do:

if (categoryId != null) 
    model.addAttribute("categoryId", categoryId);
else {
    model.remove("categoryId");
    session.removeAttribute("categoryId");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!