4b2bb00305a7b356d30cb3653a0fea0aaf51d4a2.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package org.jeecg.common.api.vo;
  2. import com.fasterxml.jackson.annotation.JsonIgnore;
  3. import io.swagger.annotations.ApiModel;
  4. import io.swagger.annotations.ApiModelProperty;
  5. import lombok.Data;
  6. import org.jeecg.common.constant.CommonConstant;
  7. import java.io.Serializable;
  8. /**
  9. * 接口返回数据格式
  10. * @author scott
  11. * @email jeecgos@163.com
  12. * @date 2019年1月19日
  13. */
  14. @Data
  15. @ApiModel(value="接口返回对象", description="接口返回对象")
  16. public class Result<T> implements Serializable {
  17. private static final long serialVersionUID = 1L;
  18. /**
  19. * 成功标志
  20. */
  21. @ApiModelProperty(value = "成功标志")
  22. private boolean success = true;
  23. /**
  24. * 返回处理消息
  25. */
  26. @ApiModelProperty(value = "返回处理消息")
  27. private String message = "操作成功!";
  28. /**
  29. * 返回代码
  30. */
  31. @ApiModelProperty(value = "返回代码")
  32. private Integer code = 0;
  33. /**
  34. * 返回数据对象 data
  35. */
  36. @ApiModelProperty(value = "返回数据对象")
  37. private T result;
  38. /**
  39. * 时间戳
  40. */
  41. @ApiModelProperty(value = "时间戳")
  42. private long timestamp = System.currentTimeMillis();
  43. public Result() {
  44. }
  45. public Result<T> success(String message) {
  46. this.message = message;
  47. this.code = CommonConstant.SC_OK_200;
  48. this.success = true;
  49. return this;
  50. }
  51. @Deprecated
  52. public static Result<Object> ok() {
  53. Result<Object> r = new Result<Object>();
  54. r.setSuccess(true);
  55. r.setCode(CommonConstant.SC_OK_200);
  56. r.setMessage("成功");
  57. return r;
  58. }
  59. @Deprecated
  60. public static Result<Object> ok(String msg) {
  61. Result<Object> r = new Result<Object>();
  62. r.setSuccess(true);
  63. r.setCode(CommonConstant.SC_OK_200);
  64. r.setMessage(msg);
  65. return r;
  66. }
  67. @Deprecated
  68. public static Result<Object> ok(Object data) {
  69. Result<Object> r = new Result<Object>();
  70. r.setSuccess(true);
  71. r.setCode(CommonConstant.SC_OK_200);
  72. r.setResult(data);
  73. return r;
  74. }
  75. public static<T> Result<T> OK() {
  76. Result<T> r = new Result<T>();
  77. r.setSuccess(true);
  78. r.setCode(CommonConstant.SC_OK_200);
  79. r.setMessage("成功");
  80. return r;
  81. }
  82. public static<T> Result<T> OK(T data) {
  83. Result<T> r = new Result<T>();
  84. r.setSuccess(true);
  85. r.setCode(CommonConstant.SC_OK_200);
  86. r.setResult(data);
  87. return r;
  88. }
  89. public static<T> Result<T> OK(String msg, T data) {
  90. Result<T> r = new Result<T>();
  91. r.setSuccess(true);
  92. r.setCode(CommonConstant.SC_OK_200);
  93. r.setMessage(msg);
  94. r.setResult(data);
  95. return r;
  96. }
  97. public static<T> Result<T> error(String msg, T data) {
  98. Result<T> r = new Result<T>();
  99. r.setSuccess(false);
  100. r.setCode(CommonConstant.SC_INTERNAL_SERVER_ERROR_500);
  101. r.setMessage(msg);
  102. r.setResult(data);
  103. return r;
  104. }
  105. public static Result<Object> error(String msg) {
  106. return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
  107. }
  108. public static Result<Object> error(int code, String msg) {
  109. Result<Object> r = new Result<Object>();
  110. r.setCode(code);
  111. r.setMessage(msg);
  112. r.setSuccess(false);
  113. return r;
  114. }
  115. public Result<T> error500(String message) {
  116. this.message = message;
  117. this.code = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
  118. this.success = false;
  119. return this;
  120. }
  121. /**
  122. * 无权限访问返回结果
  123. */
  124. public static Result<Object> noauth(String msg) {
  125. return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
  126. }
  127. @JsonIgnore
  128. private String onlTable;
  129. }