In my web project I'd like to use different specific command objects inheriting from the same abstract base class. Something like:
public abstract BaseDTO {
public String id;
public String name;
//...
}
public ADTO extends BaseDTO {
public String address;
//...
}
public BDTO extends BaseDTO {
public String phone;
//...
}
and so on...
At the moment I'm using several methods in my controller to handle each concrete command object, but it's quite annoying. I'd like to use a single method:
@PostMapping("/submit")
public String submit(@Valid @ModelAttribute("myAttribute") BaseDTO dto, BindingResult result) {
// ...
}
Is there a way to achieve this?