0

I have the following spring mvc code snippet that works fine:

Controller snippet:

@RequestMapping(value="/submitForm", method=RequestMethod.POST)
public String formSubmission(Employee employee)
{
    return "EmployeeWelcome";
}

On form data printing page:

<html>
<h4>List of Request Parameters</h4>
<h4>first name - ${employee.firstName}</h4>
<h4>last name - ${employee.lastName}</h4>
<h4>user email - ${employee.email}</h4>
<h4>user salary - ${employee.salary}</h4> 
</html>

The above prints all the values successfully, then why is the following required?

ModelMap, Model, @ModelAttribute, ModelAndView
Twenty
  • 5,234
  • 4
  • 32
  • 67

1 Answers1

1

If you want to get the model value or any message to the Ui from the java side then you would need these

You can check the details here: What are the differences between Model, ModelMap, and ModelAndView?

Check the docs: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/ModelAndView.html

Trishala
  • 26
  • 3
  • 2
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – double-beep May 22 '20 at 16:45