请求成功后放回的json字符串

Posted 今天又下下雨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请求成功后放回的json字符串相关的知识,希望对你有一定的参考价值。

/**
* 统一返回对象 封装
*
* @author SuperMudada
* @ClassName ResponseData
* @Created-Date: 2017/12/20
*/
public class ResponseData implements Serializable {

private Object data;
private String msg;
private int code;


public ResponseData(CodeEnums enums) {
this.msg = enums.getMessage();
this.code = enums.getCode();
}

public ResponseData() {
}


public ResponseData(CodeEnums enums, Object data) {
this.data = data;
this.msg = enums.getMessage();
this.code = enums.getCode();
}

public ResponseData ReturnSuccess(Object data) {
this.data = data;
this.msg = CodeEnums.SUCCESS.getMessage();
this.code = CodeEnums.SUCCESS.getCode();
return this;
}

public ResponseData ReturnSuccess() {
this.data = null;
this.msg = CodeEnums.SUCCESS.getMessage();
this.code = CodeEnums.SUCCESS.getCode();
return this;
}

public ResponseData ReturnFail(String message) {
this.data = null;
this.msg = message;
this.code = CodeEnums.INVALID.getCode();
return this;
}

public ResponseData ReturnError() {
this.data = null;
this.msg = CodeEnums.ERROR.getMessage();
this.code = CodeEnums.ERROR.getCode();
return this;
}


public Boolean ReturnIsSuccess() {
return this.code == CodeEnums.SUCCESS.getCode();
}


public Object getData() {
return data;
}

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

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;
}

@Override
public String toString() {
return "ResponseData{" +
"data=" + data +
", msg=‘" + msg + ‘\‘‘ +
", code=" + code +
‘}‘;
}
}



/**
* Created by oplus on 2017/6/8.
*/
public class AjaxMessage implements Serializable {

private String state;
private String msg;
private Object data;

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getMsg() {
return msg;
}

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

public Object getData() {
return data;
}

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

public String toJson() {
return JSON.toJSONString(this);
}


public static Builder SYS_ERR() {
return new Builder(ResponseCode.SYS_ERR);
}

public static Builder SUCC() {
return new Builder(ResponseCode.SUCC);
}


public static Builder ERR(ResponseCode responseCode) {
return new Builder(responseCode);
}

public static Builder ERR(String state, String msg) {
return new Builder(state, msg);
}

public static Builder ERR(String msg) {
return new Builder("00001", msg);
}


public AjaxMessage(Builder builder) {
this.state = builder.state;
this.msg = builder.msg;
this.data = builder.data;
}

public static class Builder {

private String state;
private String msg;
private Object data;

public Builder(ResponseCode responseCode) {
this.state = responseCode.getState();
this.msg = responseCode.getMsg();
}

public Builder(String state, String msg) {
this.state = state;
this.msg = msg;
}


public Builder code(String state) {
this.state = state;
return this;
}

public Builder message(String msg) {
this.msg = msg;
return this;
}

public Builder data(Object data) {
this.data = data;
return this;
}

public AjaxMessage build() {
return new AjaxMessage(this);
}
}


}











































































































































































































以上是关于请求成功后放回的json字符串的主要内容,如果未能解决你的问题,请参考以下文章

pandas对dataframe的数据行进行随机抽样(Random Sample of Rows):使用sample函数进行数据行随机抽样(有放回的随机抽样,replacement)

自助法随机采样过程中,对n个样本进行n次有放回的随机采样,当n趋向于无穷大时,最终有多少数据从未被选择过?

02 隐马尔可夫模型 - HMM的三个问题 - 概率计算问题

随机森林中的Bootstrap抽样是有放回抽样么?Bootstrap抽样过程描述一下

第一节 urlopen及urlretrieve

一看就懂的Tensorflow实战(随机森林)