日期:2014-05-20  浏览次数:20634 次

怎样定义对象类
现在想定义一个对象类用于获得webservice返回的数据:
  UserInfoWrapper 对象: 
  int recordNum; 
  String message;  
  UserInfo[] userInfos; //用户信息列表 
请问该怎么定义这个类

------解决方案--------------------
Java code

//作为几个bean的形势传输!
public class Test {

    public static void main(String[] args) {
        UserInfo[] user = new UserInfo[1];
        user[0].setName("zhao");
        ReflectClass r = new ReflectClass();
        r.setMessage("hello");
        r.setRecordNum(1);
        r.setUserInfos(user);
    }
}

class ReflectClass {

    private int recordNum;

    private String message;

    private UserInfo[] userInfos;

    public int getRecordNum() {
        return recordNum;
    }

    public void setRecordNum(int recordNum) {
        this.recordNum = recordNum;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public UserInfo[] getUserInfos() {
        return userInfos;
    }

    public void setUserInfos(UserInfo[] userInfos) {
        this.userInfos = userInfos;
    }

}

class UserInfo {

    private String name = null;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

------解决方案--------------------
Java code

//谢谢caoyinghui1986建议!
import java.io.Serializable;

public class Test {

    public static void main(String[] args) {
        UserInfo[] user = new UserInfo[1];
        user[0].setName("zhao");
        ReflectClass r = new ReflectClass();
        r.setMessage("hello");
        r.setRecordNum(1);
        r.setUserInfos(user);
    }
}

class ReflectClass implements Serializable {

    private int recordNum;

    private String message;

    private UserInfo[] userInfos;

    public int getRecordNum() {
        return recordNum;
    }

    public void setRecordNum(int recordNum) {
        this.recordNum = recordNum;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public UserInfo[] getUserInfos() {
        return userInfos;
    }

    public void setUserInfos(UserInfo[] userInfos) {
        this.userInfos = userInfos;
    }

}

class UserInfo implements Serializable {

    private String name = null;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}