com.gitee.fufu669.response.SimpleResponse Maven / Gradle / Ivy
package com.gitee.fufu669.response;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/** @author wangfupeng */
@ApiModel("单值返回")
public class SimpleResponse implements Serializable {
private static final long serialVersionUID = 1L;
protected static final int SUCCESS_STATUS = 200;
protected static final String SUCCESS_MESSAGE = "success";
private T data;
@ApiModelProperty(value = "返回消息,成功为success", example = "success")
private String message;
@ApiModelProperty(value = "返回状态,成功为200", example = "200")
private int status;
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public static SimpleResponse success() { return success((T) ""); }
public static SimpleResponse success(T data) {
return success(data, SUCCESS_MESSAGE, "");
}
public static SimpleResponse success(T data, String message, String moreInfo) {
return success(data, message, SUCCESS_STATUS, moreInfo);
}
public static SimpleResponse success(T data, String message, int responseStatus, String moreInfo) {
SimpleResponse response = new SimpleResponse();
response.setData(data);
response.setStatus(responseStatus);
response.setMessage(message);
return response;
}
public static SimpleResponse error(int responseStatus, String message, String moreInfo) {
SimpleResponse response = new SimpleResponse();
response.setStatus(responseStatus);
response.setMessage(message);
return response;
}
public static SimpleResponse error(int responseStatus, String message) {
return error(responseStatus, message, null);
}
public static SimpleResponse error(int responseStatus) {
return error(responseStatus, null, null);
}
}