java 封装返回值_java 封装返回结果实体类

public class ResponseMessage {

private final static String STATUS_OK = "0";

private final static String STATUS_ERROR = "1";

private String status; // 状态

private Object data; // 返回值

private Exception e; // 异常类捕获

private String msg; // 自定义信息

public String getStatus() {

return status;

}

public void setStatus(String status) {

this.status = status;

}

public Object getData() {

return data;

}

public void setData(Object data) {

this.data = data;

}

public Exception getE() {

return e;

}

public void setE(Exception e) {

this.e = e;

}

public String getMsg() {

return msg;

}

public void setMsg(String msg) {

this.msg = msg;

}

public ResponseMessage() {

super();

}

public ResponseMessage(String status, Object data, Exception e, String msg) {

super();

this.status = status;

this.data = data;

this.e = e;

this.msg = msg;

}

/**

* 成功的结果

* @param data 返回结果

* @param msg 返回信息

*/

public static ResponseMessage newOkInstance(Object data, String msg) {

return new ResponseMessage(ResponseMessage.STATUS_OK, data, null, msg);

}

/**

* 成功的结果

* @param data 返回结果

*/

public ResponseMessage newOkInstance(Object data) {

return new ResponseMessage(ResponseMessage.STATUS_OK, data, null, null);

}

/**

* 失败的结果

* @param msg 返回信息

*/

public static ResponseMessage newErrorInstance(String msg) {

return new ResponseMessage(ResponseMessage.STATUS_ERROR, null, null, msg);

}

/**

* 失败的结果

* @param e 异常对象

* @param msg 返回信息

*/

public static ResponseMessage newErrorInstance(Exception e, String msg) {

return new ResponseMessage(ResponseMessage.STATUS_ERROR, null, e, msg);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值