package com.ruoyi.common.core.domain;
|
|
|
|
import io.swagger.annotations.ApiModelProperty;
|
|
import java.io.Serializable;
|
|
|
public class Result<T> implements Serializable {
|
private static final long serialVersionUID = 1L;
|
public static final int SUCCESS = 200;
|
public static final int FAIL = 500;
|
|
@ApiModelProperty("返回内容")
|
private String msg = "成功";
|
|
@ApiModelProperty("状态码")
|
private Integer code = 0;
|
|
@ApiModelProperty("总条数")
|
private Long total = 0L;
|
|
@ApiModelProperty("数据对象")
|
private T data;
|
|
public Result() {
|
}
|
|
public Result(Integer code, String msg) {
|
this.code = code;
|
this.msg = msg;
|
}
|
|
|
public static <T> Result<T> success() {
|
Result<T> r = new Result();
|
r.setCode(0);
|
return r;
|
}
|
|
public static <T> Result<T> success(String msg) {
|
Result<T> r = new Result();
|
r.setCode(SUCCESS);
|
r.setData((T) msg);
|
return r;
|
}
|
|
public static <T> Result<T> success(T data) {
|
Result<T> r = new Result();
|
r.setCode(SUCCESS);
|
r.setData(data);
|
return r;
|
}
|
|
public static <T> Result<T> success(Long total, T data) {
|
Result<T> r = new Result();
|
r.setTotal(total);
|
r.setCode(SUCCESS);
|
r.setData(data);
|
return r;
|
}
|
|
public static <T> Result<T> success(String msg, T data) {
|
Result<T> r = new Result();
|
r.setCode(SUCCESS);
|
r.setMsg(msg);
|
r.setData(data);
|
return r;
|
}
|
|
|
public static <T> Result<T> error() {
|
return error(FAIL, "操作失败");
|
}
|
|
public static <T> Result<T> error(String msg) {
|
return error(FAIL, msg);
|
}
|
|
public static <T> Result<T> error(int code, String msg) {
|
return error(code, msg, null);
|
}
|
|
public static <T> Result<T> error(int code, String msg, T data) {
|
Result<T> r = new Result();
|
r.setCode(code);
|
r.setData(data);
|
return r;
|
}
|
|
|
|
public static <T> Result<T> noauth(String msg) {
|
return error(510, msg);
|
}
|
|
public String getMsg() {
|
return this.msg;
|
}
|
|
public Integer getCode() {
|
return this.code;
|
}
|
|
public Long getTotal() {
|
return this.total;
|
}
|
|
public T getData() {
|
return this.data;
|
}
|
|
public void setMsg(final String msg) {
|
this.msg = msg;
|
}
|
|
public void setCode(final Integer code) {
|
this.code = code;
|
}
|
|
public void setTotal(final Long total) {
|
this.total = total;
|
}
|
|
public void setData(final T data) {
|
this.data = data;
|
}
|
|
|
|
}
|