forked from admin/springboot-demo
23 lines
592 B
Java
23 lines
592 B
Java
|
|
package com.example.demo.common;
|
||
|
|
|
||
|
|
import java.time.Instant;
|
||
|
|
|
||
|
|
public record ApiResponse<T>(
|
||
|
|
int code,
|
||
|
|
String message,
|
||
|
|
T data,
|
||
|
|
Instant timestamp
|
||
|
|
) {
|
||
|
|
public static <T> ApiResponse<T> ok(T data) {
|
||
|
|
return new ApiResponse<>(0, "success", data, Instant.now());
|
||
|
|
}
|
||
|
|
|
||
|
|
public static <T> ApiResponse<T> ok(String message, T data) {
|
||
|
|
return new ApiResponse<>(0, message, data, Instant.now());
|
||
|
|
}
|
||
|
|
|
||
|
|
public static ApiResponse<Void> fail(int code, String message) {
|
||
|
|
return new ApiResponse<>(code, message, null, Instant.now());
|
||
|
|
}
|
||
|
|
}
|