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

com.swak.frame.dto.Result Maven / Gradle / Ivy

There is a newer version: 2.3.1
Show newest version
package com.swak.frame.dto;


import com.swak.frame.dto.base.VO;
import com.swak.frame.enums.BasicErrCode;
import com.swak.frame.enums.IResultCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 基础结果Result
 *
 * @author colley.ma
 * @since 2022/9/9 16:17
 */
@Setter
@Getter
@Accessors(chain = true)
public class Result implements VO {
    private static final long serialVersionUID = 7885784556539697892L;
    private Integer code;
    private String msg;
    private T data;

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public Result(T data) {
        this();
        this.data = data;
    }
    public Result(IResultCode errCode) {
        this(errCode.getCode(), errCode.getI18nMsg());
    }

    public Result(IResultCode errCode,Object...args) {
        this(errCode.getCode(), errCode.getI18nMsg(args));
    }

    public Result() {
        this(BasicErrCode.SUCCESS);
    }

    public boolean isSuccess() {
        return BasicErrCode.SUCCESS.eq(getCode());
    }

    public static   Result builder(IResultCode errCode) {
       return new Result<>(errCode);
    }

    public  static  Result fail(Integer code, String msg) {
          return new Result<>(code,msg);
    }

    public  static  Result fail(IResultCode resultCode,Object ... args) {
       return new Result<>(resultCode,args);
    }

    public static  Result success() {
        return success(null);
    }

    public static  Result success(T data) {
        return new Result<>(data);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy