1、使用泛型
2、使用子类继承父类
public class A{
private String aa;
}
public class B extends A {
private String bb;
}
public class C extends A {
private String cc;
}
chontller :
@GetMapping("/{str}",)
public A alist (Stirng str){
aservice.getA(Str)
}
Service:
public A getA(String str){
if(str.equals("n")){
return new B();
}
return new C();
}