2

I have two concrete classes, Person1 and Person2 extending Person. I want a spring jsp form to create a Person1 or a Person2.

public abstract class Person{


}


public class Person1 extends Person{

}

public class Person2 extends Person{

}

I have some field in html form describing the class type (Person1 or Person2). How can I automatically create a Person by using the @ModelAttribute annotation?

public String create(@ModelAttribute Person person){

   // person here can be instance of Person1 or Person2
   ...
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Dariush Jafari
  • 5,223
  • 7
  • 42
  • 71
  • You could have two method in controller - one with `Person1` and second with `Person2` as a `@ModelAttribute` - and just invoke shared method `controllerStuff(Person person)`. It's just a workaround, I'm sure there's a better solution – nowszy94 Feb 08 '17 at 12:26
  • this [question](http://stackoverflow.com/questions/37300586/modelattribute-and-abstract-class) could help – Sergio Feb 08 '17 at 16:44

0 Answers0