JSON string to put back after successful request

Source: Internet
Author: User
Tags getmessage

/**
* Unified Return Object Encapsulation
*
* @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 string to put back after successful request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.