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

org.macrocloud.kernel.toolkit.response.ResponseData Maven / Gradle / Ivy

There is a newer version: 1.1.0-RELEASE
Show newest version
package org.macrocloud.kernel.toolkit.response;

import java.io.Serializable;

import lombok.Data;

@Data
public class ResponseData implements Serializable {
	private static final long serialVersionUID = -2396589362283797904L;
	public static final String DEFAULT_SUCCESS_MESSAGE = "请求成功";
	public static final String DEFAULT_ERROR_MESSAGE = "网络异常";
	public static final Integer DEFAULT_SUCCESS_CODE = 200;
	public static final Integer DEFAULT_ERROR_CODE = 500;
	private Integer httpCode;
	private String message;
	private Long timestamp;
	private boolean success = true;
	private T data;

	public ResponseData() {
	}

	public ResponseData(Integer httpCode, String message, T data) {
		this.httpCode = httpCode;
		this.message = message;
		this.data = data;
		this.timestamp = System.currentTimeMillis();
	}

	public ResponseData(Integer httpCode, String message, T data, boolean success) {
		this.httpCode = httpCode;
		this.message = message;
		this.data = data;
		this.timestamp = System.currentTimeMillis();
		this.success = success;
	}

	@SuppressWarnings("unchecked")
	public static  ResponseData success(T data, String msg) {
		return new SuccessResponseData(200, msg, data);
	}

	public static SuccessResponseData success() {
		return new SuccessResponseData();
	}

	public static SuccessResponseData success(Object object) {
		return new SuccessResponseData(object);
	}

	public static SuccessResponseData success(Integer code, String message, Object object) {
		return new SuccessResponseData(code, message, object);
	}

	public static SuccessResponseData data(Object object) {
		return new SuccessResponseData(object);
	}

	public static ErrorResponseData error(String message) {
		return new ErrorResponseData(message);
	}

	public static ErrorResponseData error(Integer code, String message) {
		return new ErrorResponseData(code, message);
	}

	public static ErrorResponseData error(Integer code, String message, Object object) {
		return new ErrorResponseData(code, message, object);
	}

	@SuppressWarnings("rawtypes")
	public static  ResponseData status(boolean flag) {
		return (ResponseData) (flag ? success("操作成功") : error("操作失败"));
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy