如果我忘了庆祝春节SessionStatus AS&QUOT会发生什么;完成"? [英] What happens if I forget to mark the Spring SessionStatus as "Complete"?

查看:126
本文介绍了如果我忘了庆祝春节SessionStatus AS&QUOT会发生什么;完成"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring MVC中,假设我定义了一个SessionAttribute,使用@SessionAttribute标签,像这样:

In Spring MVC, suppose I define a SessionAttribute, using the @SessionAttribute tag like so:

@SessionAttributes(value = "myModel")
public class MyController{
   ...
}

假设我忘了在SessionStatus喜欢这么称呼status.setComplete():

Suppose that I forget to call status.setComplete() on the SessionStatus like so:

@RequestMapping(method = RequestMethod.POST)
public void doSomething(@ModelAttribute("myModel") MyModel model, SessionStatus status){
   ...
   //status.setComplete(); <-- Never gets called
}

请问模型停留在会议下去吗?将以往任何时候都得到清理,或将在本届会议继续增长越来越大当用户浏览网站?

Will the model stay in the session forever? Will it ever get cleaned out, or will the session keep growing larger and larger as the user navigates the site?

推荐答案

编辑#2:请注意,这个答案是不再正确。见下面@ doanduyhai的回答。

EDIT #2: Note that this answer is no longer correct. See @doanduyhai's answer below.

编辑:请注意,这是对Spring 2.5,并且可以,但并不一定确保相同为弹簧3.x的仔细检查文档!

Please note that this is for Spring 2.5 and may, but does not necessarily ensure that the same is for Spring 3.x. Double check the docs!

这是一起什么@Gandalf说行。

This is along the lines of what @Gandalf said.

用控制器模型的形式要求寿命,从表单的初始观看通过表单提交。在提交表单后,表单控制器的工作已经完成,它会从会话删除命令对象。

Form controllers model a form request lifespan, from initial viewing of the form through form submission. After the form is submitted, the form controller's job is done, and it will remove the command object from the session.

所以,为了保持命令对象,你将需要手动管理会话形式的工作流之间的会话。干净的POST之后,对象从会话中删除。

So, to keep the command object in the session between form workflows you will need to manage the session manually. After a clean POST, the object is removed from session.

总之,我相信setComplete()方法方法就是很好的做法,但不是必需的。

In short, I believe the setComplete() method is just good practice but is not necessarily required.

修改:我只是看着我的春天书中证实了这一点。我会引用它:

EDIT: I just looked in my Spring book to confirm this. I'll quote it:

当不使用@SessionAttribute,一个
  新的命令对象将被创建在
  每个请求,渲染即使当
  再次形成,由于绑定错误。如果
  这个注解被启用,
  命令对象将被存储在
  会议的后续使用,直到
  形式成功完成。然后
  该命令对象将被清除
  从会话。
这通常是
  当命令对象是使用
  一个需要持久化对象
  在不同的要求相同
  跟踪变化。

When @SessionAttribute is not used, a new command object will be created on each request, even when rendering the form again due to binding errors. If this annotation is enabled, the command object will be stored in the session for subsequent uses, until the form completes successfully. Then this command object will be cleared from the session. This is usually used when the command object is a persistent object that needs to be identical across different requests for tracking changes.

从本质上讲,这就是我上面说。它存储在会话中,直到你要么A)调用SetComplete()或B)控制器成功完成一个POST。

Essentially that's what I was saying above. It stores it in the session until you either A) call setComplete() or B) the controller successfully completes a POST.

这篇关于如果我忘了庆祝春节SessionStatus AS&QUOT会发生什么;完成&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆