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

com.github.leeyazhou.akshare4j.util.http.rpc.model.Result Maven / Gradle / Ivy

The newest version!
package com.github.leeyazhou.akshare4j.util.http.rpc.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Result implements Serializable {
  private static final long serialVersionUID = 1L;

  private int code = 1000;

  private String message = "OK";
  private T data;
  private String traceid;

  public int getCode() {
    return code;
  }

  public Result setCode(int code) {
    this.code = code;
    return this;
  }

  public String getMessage() {
    return message;
  }

  public Result setMessage(String message) {
    this.message = message;
    return this;
  }

  public T getData() {
    return data;
  }

  public Result setData(T data) {
    this.data = data;
    return this;
  }

  @SuppressWarnings("unchecked")
  public Result addAttribute(String name, Object attr) {
    if (this.data == null) {
      this.data = (T) new HashMap();
    }
    ((Map) data).put(name, attr);
    return this;
  }

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

  public static  Result success(T data) {
    return new Result().setData(data);
  }

  public static  Result fail() {
    return new Result().setCode(5000).setMessage("fail");
  }

  public static  Result fail(int code, String message) {
    return new Result().setCode(code).setMessage(message);
  }

  public static  Result fail(String message) {
    return new Result().setCode(5000).setMessage(message);
  }

  public String getTraceid() {
    // if (this.traceid == null) {
    // this.traceid = TraceIdContext.get();
    // }
    return traceid;
  }

  public void setTraceid(String traceid) {
    this.traceid = traceid;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy