12 lines
257 B
Python
12 lines
257 B
Python
from typing import TypeVar, Generic
|
|
|
|
from pydantic import BaseModel
|
|
|
|
# 声明一个泛型类型变量
|
|
T = TypeVar("T")
|
|
|
|
# 泛型响应体
|
|
class ApiResponse(BaseModel, Generic[T]):
|
|
code: int
|
|
message: str
|
|
data: T | None = None # data可以为空 |