如何在spring-mvc控制器中区分命令对象?例如,我有以下bean类用作表单对象:
public class CreateServiceFormBean {
@NotBlank
@Length(min = 3, max = 120)
private String name;
}
public class CreateDependedServiceFormBean extends CreateServiceFormBean {
@NotNull
private Short parentServiceId;
}
Getter&Setter&#39>被切断了。
@RequestMapping(method = RequestMethod.POST)
public String createService(CreateServiceFormBean form) {
if (form instanceof CreateServiceFormBean) {
System.out.println("create Service");
//new ServiceEntity(form.getName())
} else if (form instanceof CreateDependedServiceFormBean) {
System.out.println("create depended Service");
parentService = ... get parent service entity...
//new DependedServiceEntity(form.getName(), parentService)
}
return null;
}
这是怎么回事?我想为这两个dto创建抽象控制器,但不优雅..可以用一种方法处理.. 以及如何纠正获取父服务实体?有些像方法ModelAttribute注释,其返回实体由id?
感谢回复!