后台服务
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

76 wiersze
1.9 KiB

  1. package com.iformall.common;
  2. import io.swagger.annotations.ApiModel;
  3. import io.swagger.annotations.ApiModelProperty;
  4. import lombok.Data;
  5. import java.io.Serializable;
  6. /**
  7. * 响应信息主体
  8. *
  9. * @author xmzhao71
  10. * @date 2023-10-26
  11. */
  12. @ApiModel(description = "响应信息主体")
  13. @Data
  14. public class R<T> implements Serializable {
  15. private static final long serialVersionUID = 1L;
  16. @ApiModelProperty(value = "返回标记:成功=0,失败=1")
  17. private int code;
  18. @ApiModelProperty(value = "返回信息")
  19. private String message;
  20. @ApiModelProperty(value = "数据")
  21. private T data;
  22. public Boolean isOk() {
  23. return code == 200;
  24. }
  25. public static <T> R<T> ok() {
  26. return restResult(null, CommonConstants.SUCCESS, null);
  27. }
  28. public static <T> R<T> ok(T data) {
  29. return restResult(data, CommonConstants.SUCCESS, null);
  30. }
  31. public static <T> R<T> ok(T data, String msg) {
  32. return restResult(data, CommonConstants.SUCCESS, msg);
  33. }
  34. public static <T> R<T> failed() {
  35. return restResult(null, CommonConstants.FAILED, null);
  36. }
  37. public static <T> R<T> failed(String msg) {
  38. return restResult(null, CommonConstants.FAILED, msg);
  39. }
  40. public static <T> R<T> failed(T data) {
  41. return restResult(data, CommonConstants.FAILED, null);
  42. }
  43. public static <T> R<T> failed(T data, String msg) {
  44. return restResult(data, CommonConstants.FAILED, msg);
  45. }
  46. public static <T> R<T> failed(T data, int code, String msg) {
  47. return restResult(data, code, msg);
  48. }
  49. public static <T> R<T> failed(int code, String msg) {
  50. return restResult(null, code, msg);
  51. }
  52. private static <T> R<T> restResult(T data, int code, String msg) {
  53. R<T> apiResult = new R<>();
  54. apiResult.setCode(code);
  55. apiResult.setData(data);
  56. apiResult.setMessage(msg);
  57. return apiResult;
  58. }
  59. }