|
- package com.iformall.common;
-
- import io.swagger.annotations.ApiModel;
- import io.swagger.annotations.ApiModelProperty;
- import lombok.Data;
-
- import java.io.Serializable;
-
- /**
- * 响应信息主体
- *
- * @author xmzhao71
- * @date 2023-10-26
- */
- @ApiModel(description = "响应信息主体")
- @Data
- public class R<T> implements Serializable {
- private static final long serialVersionUID = 1L;
-
- @ApiModelProperty(value = "返回标记:成功=0,失败=1")
- private int code;
-
- @ApiModelProperty(value = "返回信息")
- private String message;
-
- @ApiModelProperty(value = "数据")
- private T data;
-
- public Boolean isOk() {
- return code == 200;
- }
-
- public static <T> R<T> ok() {
- return restResult(null, CommonConstants.SUCCESS, null);
- }
-
- public static <T> R<T> ok(T data) {
- return restResult(data, CommonConstants.SUCCESS, null);
- }
-
- public static <T> R<T> ok(T data, String msg) {
- return restResult(data, CommonConstants.SUCCESS, msg);
- }
-
- public static <T> R<T> failed() {
- return restResult(null, CommonConstants.FAILED, null);
- }
-
- public static <T> R<T> failed(String msg) {
- return restResult(null, CommonConstants.FAILED, msg);
- }
-
- public static <T> R<T> failed(T data) {
- return restResult(data, CommonConstants.FAILED, null);
- }
-
- public static <T> R<T> failed(T data, String msg) {
- return restResult(data, CommonConstants.FAILED, msg);
- }
-
- public static <T> R<T> failed(T data, int code, String msg) {
- return restResult(data, code, msg);
- }
-
- public static <T> R<T> failed(int code, String msg) {
- return restResult(null, code, msg);
- }
-
- private static <T> R<T> restResult(T data, int code, String msg) {
- R<T> apiResult = new R<>();
- apiResult.setCode(code);
- apiResult.setData(data);
- apiResult.setMessage(msg);
- return apiResult;
- }
- }
|