重写复现方法
This commit is contained in:
52
src/main/java/com/mini/capi/model/auth/Result.java
Normal file
52
src/main/java/com/mini/capi/model/auth/Result.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.mini.capi.model.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class Result implements Serializable {
|
||||
|
||||
// 状态码:200表示成功,其他表示错误
|
||||
private int code;
|
||||
// 响应信息
|
||||
private String msg;
|
||||
// 响应数据(可选)
|
||||
private Object data;
|
||||
|
||||
// 私有构造方法,防止直接创建实例
|
||||
private Result() {}
|
||||
|
||||
// 成功响应
|
||||
public static Result success(String msg) {
|
||||
Result result = new Result();
|
||||
result.code = 200;
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 带数据的成功响应
|
||||
public static Result success(String msg, Object data) {
|
||||
Result result = new Result();
|
||||
result.code = 200;
|
||||
result.msg = msg;
|
||||
result.data = data;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 错误响应
|
||||
public static Result error(String msg) {
|
||||
Result result = new Result();
|
||||
result.code = 500; // 500表示服务器错误,也可以根据实际情况使用其他错误码
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 带自定义错误码的错误响应
|
||||
public static Result error(int code, String msg) {
|
||||
Result result = new Result();
|
||||
result.code = code;
|
||||
result.msg = msg;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user