Result.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. package com.template.model.result;
  3. import com.flyhigh.common.config.CoreConstant;
  4. import com.flyhigh.common.exception.CustomizeException;
  5. import io.swagger.annotations.ApiModel;
  6. import io.swagger.annotations.ApiModelProperty;
  7. import lombok.AllArgsConstructor;
  8. import lombok.Data;
  9. import lombok.NoArgsConstructor;
  10. import java.io.Serializable;
  11. */
  12. /**
  13. * 请求响应数据
  14. *
  15. * @param <T> 数据类型
  16. *//*
  17. @Data
  18. @AllArgsConstructor
  19. @NoArgsConstructor
  20. @ApiModel("请求响应数据")
  21. public class Result<T> implements Serializable {
  22. */
  23. /**
  24. * 数据
  25. *//*
  26. @ApiModelProperty("数据")
  27. private T data;
  28. */
  29. /**
  30. * 信息
  31. *//*
  32. @ApiModelProperty("信息")
  33. private String message;
  34. */
  35. /**
  36. * 状态码
  37. *//*
  38. @ApiModelProperty("状态码")
  39. private int code;
  40. public static <T> Result<T> ok() {
  41. return new Result<>(null, "" , 200);
  42. }
  43. public static <T> Result<T> ok(T data) {
  44. return new Result<>(data, "" , 200);
  45. }
  46. public static <T> Result<T> ok(T data, String message) {
  47. return new Result<>(data, message, 200);
  48. }
  49. public static <T> Result<T> fail(String message, int code) {
  50. return new Result<>(null, message, code);
  51. }
  52. public static <T> Result<T> fail(T data, String message, int code) {
  53. return new Result<>(data, message, code);
  54. }
  55. public static <T> Result<T> fail(CustomizeException e) {
  56. return new Result<>(null, e.getMessage(), e.getCode());
  57. }
  58. public static <T> Result<T> failClient(String message) {
  59. return new Result<>(null, message, CoreConstant.CLIENT_LOGIC_ERROR);
  60. }
  61. public static <T> Result<T> failSystem(String message) {
  62. return new Result<>(null, message, CoreConstant.SERVER_LOGIC_ERROR);
  63. }
  64. }
  65. */