No.1


import java.util.HashMap;
import java.util.Map;

/**
 * 接口返回数据
 * 
 * @author hzqq
 *  
 */
public class ResultBean extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public ResultBean() {
		put("code", 0);
		put("msg", "");
		put("data", null);
	}

	public static ResultBean error() {
		return error(500, "未知异常,请联系管理员");
	}

	public static ResultBean error(String msg) {
		return error(500, msg);
	}

	public static ResultBean error(int code, String msg) {
		ResultBean r = new ResultBean();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static ResultBean ok() {
		return new ResultBean();
	}

	public static ResultBean ok(String msg) {
		ResultBean r = new ResultBean();
		r.put("msg", msg);
		return r;
	}

	public static ResultBean ok(Map<String, Object> map) {
		ResultBean r = new ResultBean();
		r.putAll(map);
		return r;
	}

	public static ResultBean ok(Object obj) {
		return new ResultBean().put("data", obj);
	}

	public ResultBean put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}

No.2




public class ResultBean<T> implements Serializable {
    public static final int SUCCESS = 0;
    public static final int FAIL = -1;

    private String msg = "SUCCESS";
    private int code = SUCCESS;
    private T data;

    public ResultBean() {
        super();
    }

    public ResultBean(T data) {
        super();
        this.data = data;
    }

    public ResultBean(Throwable e) {
        super();
        this.msg = e.getMessage();
        this.code = FAIL;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}