初始化3

master
TangZhaoZhen 2023-10-18 09:20:14 +08:00
parent 245c1d8a83
commit f41a229fbb
1 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,105 @@
package com.tongcheng.common.core.domain;
import java.io.Serializable;
import com.tongcheng.common.core.constant.Constants;
/**
*
*
* @author tongcheng
*/
public class Result<T> implements Serializable
{
private static final long serialVersionUID = 1L;
/** 成功 */
public static final int SUCCESS = Constants.SUCCESS;
/** 失败 */
public static final int ERROR = Constants.ERROR;
private int code;
private String msg;
private T data;
public static <T> Result<T> success()
{
return restResult(null, SUCCESS, null);
}
public static <T> Result<T> success(T data)
{
return restResult(data, SUCCESS, null);
}
public static <T> Result<T> success(T data, String msg)
{
return restResult(data, SUCCESS, msg);
}
public static <T> Result<T> error()
{
return restResult(null, ERROR, null);
}
public static <T> Result<T> error(String msg)
{
return restResult(null, ERROR, msg);
}
public static <T> Result<T> error(T data)
{
return restResult(data, ERROR, null);
}
public static <T> Result<T> error(T data, String msg)
{
return restResult(data, ERROR, msg);
}
public static <T> Result<T> error(int code, String msg)
{
return restResult(null, code, msg);
}
private static <T> Result<T> restResult(T data, int code, String msg)
{
Result<T> apiResult = new Result<>();
apiResult.setCode(code);
apiResult.setData(data);
apiResult.setMsg(msg);
return apiResult;
}
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;
}
}