How to pass model attributes from one Spring MVC controller to another controller?

I use spring 3.2.3 and here is how I solved similar problem. 1) Added RedirectAttributes redirectAttributes to the method parameter list in controller 1. public String controlMapping1( @ModelAttribute(“mapping1Form”) final Object mapping1FormObject, final BindingResult mapping1BindingResult, final Model model, final RedirectAttributes redirectAttributes) 2) Inside the method added code to add flash attribute to redirectAttributes redirectAttributes.addFlashAttribute(“mapping1Form”, mapping1FormObject); 3) … Read more

Difference between modelAttribute and commandName attributes in form tag in spring?

If you look at the source code of FormTag (4.3.x) which backs your <form> element, you’ll notice this /** * Set the name of the form attribute in the model. * <p>May be a runtime expression. */ public void setModelAttribute(String modelAttribute) { this.modelAttribute = modelAttribute; } /** * Get the name of the form attribute … Read more

What is @ModelAttribute in Spring MVC?

@ModelAttribute refers to a property of the Model object (the M in MVC 😉 so let’s say we have a form with a form backing object that is called “Person” Then you can have Spring MVC supply this object to a Controller method by using the @ModelAttribute annotation: public String processForm(@ModelAttribute(“person”) Person person){ person.getStuff(); } … Read more