🔄Update: 增加响应包装类
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package cn.hezhaohui.thumb.common;
|
||||
|
||||
import cn.hezhaohui.thumb.exception.ErrorCode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class BaseResponse<T> implements Serializable {
|
||||
|
||||
private int code;
|
||||
|
||||
private T data;
|
||||
|
||||
private String message;
|
||||
|
||||
|
||||
public BaseResponse(int code, T data, String message) {
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public BaseResponse(int code, T data) {
|
||||
this(code, data, "");
|
||||
}
|
||||
|
||||
public BaseResponse(ErrorCode errorCode) {
|
||||
this(errorCode.getCode(), null, errorCode.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.hezhaohui.thumb.common;
|
||||
|
||||
import cn.hezhaohui.thumb.exception.ErrorCode;
|
||||
|
||||
public class ResultUtils {
|
||||
|
||||
public static <T> BaseResponse<T> sucess(T data) {
|
||||
return new BaseResponse<>(ErrorCode.SUCCESS.getCode(), data, ErrorCode.SUCCESS.getMessage());
|
||||
}
|
||||
|
||||
public static BaseResponse<?> error(ErrorCode errorCode) {
|
||||
return new BaseResponse<>(errorCode);
|
||||
}
|
||||
|
||||
public static BaseResponse<?> error(int code, String message) {
|
||||
return new BaseResponse<>(code, null, message);
|
||||
}
|
||||
|
||||
public static BaseResponse<?> error(ErrorCode errorCode, String message) {
|
||||
return new BaseResponse<>(errorCode.getCode(), null, message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user