61 lines
1.4 KiB
Java
61 lines
1.4 KiB
Java
|
package com.example.myapplication.model;
|
|||
|
|
|||
|
import com.google.gson.annotations.SerializedName;
|
|||
|
|
|||
|
public class ApiResponse<T> {
|
|||
|
|
|||
|
|
|||
|
|
|||
|
@SerializedName("code")
|
|||
|
private int code;
|
|||
|
|
|||
|
@SerializedName("msg")
|
|||
|
private String msg; // 严格匹配服务器字段名 "msg"
|
|||
|
|
|||
|
@SerializedName("data")
|
|||
|
private T data;
|
|||
|
|
|||
|
@SerializedName("status")
|
|||
|
private int status;
|
|||
|
|
|||
|
@SerializedName("success")
|
|||
|
private boolean success;
|
|||
|
|
|||
|
// Getters
|
|||
|
public int getCode() {
|
|||
|
return code;
|
|||
|
}
|
|||
|
|
|||
|
public String getMsg() { // 方法名改为 getMsg() 与字段名一致
|
|||
|
return msg;
|
|||
|
}
|
|||
|
|
|||
|
public T getData() {
|
|||
|
return data;
|
|||
|
}
|
|||
|
|
|||
|
public int getStatus() {
|
|||
|
return status;
|
|||
|
}
|
|||
|
|
|||
|
public boolean isSuccess() {
|
|||
|
return success;
|
|||
|
}
|
|||
|
|
|||
|
// Setters(按需添加)
|
|||
|
public void setData(T data) {
|
|||
|
this.data = data;
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public String toString() {
|
|||
|
return "ApiResponse{" +
|
|||
|
"code=" + code +
|
|||
|
", msg='" + msg + '\'' +
|
|||
|
", data=" + data +
|
|||
|
", status=" + status +
|
|||
|
", success=" + success +
|
|||
|
'}';
|
|||
|
}
|
|||
|
|
|||
|
}
|