I'm new to spring, so sorry if this is a newbies question, but the manual is not clear (at least not for me)
My question is: how do I share state between requests in spring? I can send data from the controller to the view using ModelMap, but the data in ModelMap will not be sent back to the next controller using the view. How to do it with spring?
The following is part of my source code. In the second controller, modelMap does not contain the data that I saved in modelMap in the first controller. How should I maintain state between controllers in spring?
Many thanks for the help.
@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">
...
</form:form>
@RequestMapping(value = "bla", method = RequestMethod.POST)
public String bla(@ModelAttribute("data") Data data, BindingResult result, ModelMap modelMap) {
System.out.println(modelMap);
}
source
share