在请求之间保持弹簧状态

编程入门 行业动态 更新时间:2024-10-07 15:20:32
本文介绍了在请求之间保持弹簧状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

在请求之间保持弹簧状态

本文发布于:2023-11-12 14:27:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹簧   状态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!