package com.iailab.module.data.common.utils;
|
|
import com.iailab.framework.common.enums.ErrorCode;
|
|
import java.io.Serializable;
|
|
/**
|
* 响应数据
|
*
|
* @author Mark sunlightcs@gmail.com
|
* @since 1.0.0
|
*/
|
public class Result<T> implements Serializable {
|
private static final long serialVersionUID = 1L;
|
/**
|
* 编码:0表示成功,其他值表示失败
|
*/
|
private int code = 0;
|
/**
|
* 消息内容
|
*/
|
private String msg = "success";
|
/**
|
* 响应数据
|
*/
|
private T data;
|
|
public Result<T> ok(T data) {
|
this.setData(data);
|
return this;
|
}
|
|
public boolean success(){
|
return code == 0;
|
}
|
|
public Result<T> error() {
|
this.code = ErrorCode.INTERNAL_SERVER_ERROR;
|
this.msg = MessageUtils.getMessage(this.code);
|
return this;
|
}
|
|
public Result<T> error(int code) {
|
this.code = code;
|
this.msg = MessageUtils.getMessage(this.code);
|
return this;
|
}
|
|
public Result<T> error(int code, String msg) {
|
this.code = code;
|
this.msg = msg;
|
return this;
|
}
|
|
public Result<T> error(String msg) {
|
this.code = ErrorCode.INTERNAL_SERVER_ERROR;
|
this.msg = msg;
|
return this;
|
}
|
|
public int getCode() {
|
return code;
|
}
|
|
public void setCode(int code) {
|
this.code = code;
|
}
|
|
public String getMsg() {
|
return msg;
|
}
|
|
public void setMsg(String msg) {
|
this.msg = msg;
|
}
|
|
public T getData() {
|
return data;
|
}
|
|
public void setData(T data) {
|
this.data = data;
|
}
|
}
|