在请求之间保持弹簧状态 [英] maintain state with spring between requests

查看:100
本文介绍了在请求之间保持弹簧状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的春天很抱歉,如果这是一个初学者的问题,但手册不清楚(至少不适合我)

I am new to spring so sorry if this is a beginners question, but the manual is not clear (at least not for me)

我的问题是:如何我在春天的请求之间分享状态吗?
我可以使用ModelMap将数据从控制器发送到视图,但是ModelMap中的数据不会被视图发送回下一个控制器。
如何使用spring执行此操作?

My question is: how do I share state between requests in spring? I can send data from the controller to the view by using a ModelMap, but the data in the ModelMap is not sent back to the next controller by the view. How can I do this with spring?

以下是我的源代码的一部分。在第二个控制器中,modelMap不包含我在第一个控制器中存储在modelMap中的数据。
我怎么能在春季保持控制器之间的状态?

Below is a part of my source code. In the second controller the modelMap doesn't contain the data I stored in the modelMap in the first controller. How am I supposed to maintain state between controllers in spring?

非常感谢你的帮助。

@RequestMapping(value = "find/something", method = RequestMethod.GET)
public String foo(@RequestParam("parent") Parent parent, ModelMap modelMap) {    
...
    modelMap.addAttribute("question_index", 42);
    modelMap.addAttribute("something", new Something());
    modelMap.addAttribute("data", new Data());
    return "some/view";
}

<form:form action="bla" method="POST"  modelAttribute="data">
...// using Something() and 42
</form:form>

@RequestMapping(value = "bla", method = RequestMethod.POST)    
public String bla(@ModelAttribute("data") Data data, BindingResult result, ModelMap modelMap) {
System.out.println(modelMap); // doesn't contain question_index, or something
}


推荐答案

您可以将modelMap放在 HttpSession 中,或者(对于大型应用程序更好),使用 Spring网络流程,您可以进行所谓的对话。

You can either put the modelMap in the HttpSession, or (preferable for larger applications), use Spring web flow where you can have the so called conversations.

这篇关于在请求之间保持弹簧状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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