123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package org.jeecg.common.api.vo;
- import com.fasterxml.jackson.annotation.JsonIgnore;
- import io.swagger.annotations.ApiModel;
- import io.swagger.annotations.ApiModelProperty;
- import lombok.Data;
- import org.jeecg.common.constant.CommonConstant;
- import java.io.Serializable;
- /**
- * 接口返回数据格式
- * @author scott
- * @email jeecgos@163.com
- * @date 2019年1月19日
- */
- @Data
- @ApiModel(value="接口返回对象", description="接口返回对象")
- public class Result<T> implements Serializable {
- private static final long serialVersionUID = 1L;
- /**
- * 成功标志
- */
- @ApiModelProperty(value = "成功标志")
- private boolean success = true;
- /**
- * 返回处理消息
- */
- @ApiModelProperty(value = "返回处理消息")
- private String message = "操作成功!";
- /**
- * 返回代码
- */
- @ApiModelProperty(value = "返回代码")
- private Integer code = 0;
-
- /**
- * 返回数据对象 data
- */
- @ApiModelProperty(value = "返回数据对象")
- private T result;
-
- /**
- * 时间戳
- */
- @ApiModelProperty(value = "时间戳")
- private long timestamp = System.currentTimeMillis();
- public Result() {
-
- }
-
- public Result<T> success(String message) {
- this.message = message;
- this.code = CommonConstant.SC_OK_200;
- this.success = true;
- return this;
- }
- @Deprecated
- public static Result<Object> ok() {
- Result<Object> r = new Result<Object>();
- r.setSuccess(true);
- r.setCode(CommonConstant.SC_OK_200);
- r.setMessage("成功");
- return r;
- }
- @Deprecated
- public static Result<Object> ok(String msg) {
- Result<Object> r = new Result<Object>();
- r.setSuccess(true);
- r.setCode(CommonConstant.SC_OK_200);
- r.setMessage(msg);
- return r;
- }
- @Deprecated
- public static Result<Object> ok(Object data) {
- Result<Object> r = new Result<Object>();
- r.setSuccess(true);
- r.setCode(CommonConstant.SC_OK_200);
- r.setResult(data);
- return r;
- }
- public static<T> Result<T> OK() {
- Result<T> r = new Result<T>();
- r.setSuccess(true);
- r.setCode(CommonConstant.SC_OK_200);
- r.setMessage("成功");
- return r;
- }
- public static<T> Result<T> OK(T data) {
- Result<T> r = new Result<T>();
- r.setSuccess(true);
- r.setCode(CommonConstant.SC_OK_200);
- r.setResult(data);
- return r;
- }
- public static<T> Result<T> OK(String msg, T data) {
- Result<T> r = new Result<T>();
- r.setSuccess(true);
- r.setCode(CommonConstant.SC_OK_200);
- r.setMessage(msg);
- r.setResult(data);
- return r;
- }
- public static<T> Result<T> error(String msg, T data) {
- Result<T> r = new Result<T>();
- r.setSuccess(false);
- r.setCode(CommonConstant.SC_INTERNAL_SERVER_ERROR_500);
- r.setMessage(msg);
- r.setResult(data);
- return r;
- }
- public static Result<Object> error(String msg) {
- return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
- }
-
- public static Result<Object> error(int code, String msg) {
- Result<Object> r = new Result<Object>();
- r.setCode(code);
- r.setMessage(msg);
- r.setSuccess(false);
- return r;
- }
- public Result<T> error500(String message) {
- this.message = message;
- this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
- this.success = false;
- return this;
- }
- /**
- * 无权限访问返回结果
- */
- public static Result<Object> noauth(String msg) {
- return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
- }
- @JsonIgnore
- private String onlTable;
- }
|