Search code examples
formsjspspring-mvcmodelattribute

Multiple modelattributes in a JSP with Spring


What I am trying to accomplish is using one single form, submit multiple modelattributes with Spring and JSP.

With one I know how to do it, mapping the model with the tag form:form.

But, if I want to get two modelAttributes in the controller method with the annotations @ModelAttribute how should I do it? Is it even possible? I am aware this is not so common, but I would like to know if it is possible.


Solution

  • AFAIK, you can only bind a form with a single object. If you have two classes, then you can create a single class that references the other two classes and then bind with that class.