1

Why in the example without any annotations the POST handler recieves the populated instance of the form?

How Spring MVC figures it out to make the binding between the model attribute and the parameter in the POST method?

@RequestMapping( value = "/myurl", method = RequestMethod.GET )
public String setView(Model model) {
    MyClass instance = new MyClass();
    model.addAttribute("viewParameter", instance );
    return TEMPLATE_PATH;
}

@RequestMapping( value = "/myurl", method = RequestMethod.POST)    
public String handleReqest(MyClass instance,  Model model) {
  // Why instance is populated out of the box
}
kidwon
  • 4,448
  • 5
  • 28
  • 45
  • if you don't specify the HTTP method, it will calls that handler method for any HTTP method. – nnunes10 Mar 14 '16 at 17:26
  • Possibly a duplicate of [What is ModelAttribute in Spring?](http://stackoverflow.com/questions/3423262/what-is-modelattribute-in-spring-mvc) – Sanjay Rawat Mar 14 '16 at 21:19
  • I'm not sure what you want to know. The form's fields are mapped to the object's properties. It's the default behavior when the client posts a form. – a better oliver Mar 15 '16 at 19:00

0 Answers0