0

我在 Java 中使用 Web 服务。这是我的问题:

public Object execute(int servicecode)
{
    switch (servicecode)
    {
        case 1:
           return OBJECT_1;
        case 2:
           return OBJECT_2;
        case 3:
           return OBJECT_3;
    }
}
  • 我的函数返回 OBJECT_1、OBJECT_2、OBJECT_3。我希望客户了解:
    • 案例 1 对象=OBJECT_1
    • 案例 2 对象=OBJECT_2
    • 案例 3 对象=OBJECT_3

我如何在 Web 服务中做到这一点?我尝试在 Web 服务中使用继承,但无法获取 OBJECT_1、OBJECT_2、OBJECT_3 的属性。

4

1 回答 1

0

是的,如果 OBJECT_1,OBJECT_2,OBJECT_3 有不同的类型,那么......你可以这样做......


public class Object {
// here we are creating a class who has all objects you want to return, 
    // this is called wrapper class
private Object_1 object_1;
private Object_2 object_1;
private Object_3 object_1;
public Object_1 getObject_1() {
    return object_1;
}
public void setObject_1(Object_1 object_1) {
    this.object_1 = object_1;
}
public Object_2 getObject_1() {
    return object_1;
}
public void setObject_1(Object_2 object_1) {
    this.object_1 = object_1;
}
public Object_3 getObject_1() {
    return object_1;
}
public void setObject_1(Object_3 object_1) {
    this.object_1 = object_1;
}   

}

public class Test{ 
public Object execute(int servicecode)
{
    Object object = new Object();
    switch (servicecode)
    {
        case 1:
           return object.setObject_1(object_1);
        case 2:
           return object.setObject_2(object_2);;
        case 3:
           return object.setObject_3(object_3);;
    }
}

}

于 2012-05-23T10:55:07.540 回答