我是新来的春天很抱歉,如果这是一个初学者的问题,但手册不清楚(至少不适合我)
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.
更多推荐
在请求之间保持弹簧状态
发布评论