All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zyy.common.util.ApiResult Maven / Gradle / Ivy

package com.zyy.common.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * Created by zlp on 2020/02/25
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ApiResult {
    private int code;
    private T data;
    private String message;

    public void setApiCode(ApiCode apiCode) {
        this.code = apiCode.getCode();
        this.message = apiCode.getMessage();
    }

    public static  ApiResult success(T data) {
        ApiResult result = new ApiResult<>();
        result.setApiCode(ApiCode.SUCCESS);
        result.setData(data);
        return result;
    }


    public static  ApiResult success() {
        ApiResult result = new ApiResult<>();
        result.setApiCode(ApiCode.SUCCESS);
        return result;
    }

    public static  ApiResult fail() {
        ApiResult result = new ApiResult<>();
        result.setApiCode(ApiCode.FAILURE);
        return result;
    }

    public static  ApiResult fail(ApiCode apiCode) {
        ApiResult result = new ApiResult<>();
        result.setApiCode(apiCode);
        return result;
    }

    public static  ApiResult fail(String msg) {
        ApiResult result = new ApiResult<>();
        result.setApiCode(ApiCode.FAILURE);
        result.setMessage(msg);
        return result;
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy