feat: 基础修改
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.webgame.webgamebackend.common.dto;
|
||||
|
||||
/**
|
||||
* 后端统一响应格式
|
||||
*
|
||||
* @param <T> 响应数据类型
|
||||
*/
|
||||
public record ApiResponse<T>(int code, String message, T data) {
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
*
|
||||
* @param data 响应数据
|
||||
* @param <T> 数据类型
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public static <T> ApiResponse<T> ok(T data) {
|
||||
return new ApiResponse<>(0, "success", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败响应
|
||||
*
|
||||
* @param code 业务状态码
|
||||
* @param message 错误消息
|
||||
* @param <T> 数据类型
|
||||
* @return ApiResponse
|
||||
*/
|
||||
public static <T> ApiResponse<T> fail(int code, String message) {
|
||||
return new ApiResponse<>(code, message, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user