You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Result.java 1.5 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.xkcoding.elasticsearch.model;
  2. import lombok.Data;
  3. import org.springframework.lang.Nullable;
  4. import java.io.Serializable;
  5. /**
  6. * Result
  7. *
  8. * @author fxbin
  9. * @version v1.0
  10. * @since 2019/8/26 1:44
  11. */
  12. @Data
  13. public class Result<T> implements Serializable {
  14. private static final long serialVersionUID = 1696194043024336235L;
  15. /**
  16. * 错误码
  17. */
  18. private int errcode;
  19. /**
  20. * 错误信息
  21. */
  22. private String errmsg;
  23. /**
  24. * 响应数据
  25. */
  26. private T data;
  27. public Result() {
  28. }
  29. private Result(ResultCode resultCode) {
  30. this(resultCode.code, resultCode.msg);
  31. }
  32. private Result(ResultCode resultCode, T data) {
  33. this(resultCode.code, resultCode.msg, data);
  34. }
  35. private Result(int errcode, String errmsg) {
  36. this(errcode, errmsg, null);
  37. }
  38. private Result(int errcode, String errmsg, T data) {
  39. this.errcode = errcode;
  40. this.errmsg = errmsg;
  41. this.data = data;
  42. }
  43. /**
  44. * 返回成功
  45. *
  46. * @param <T> 泛型标记
  47. * @return 响应信息 {@code Result}
  48. */
  49. public static <T> Result<T> success() {
  50. return new Result<>(ResultCode.SUCCESS);
  51. }
  52. /**
  53. * 返回成功-携带数据
  54. *
  55. * @param data 响应数据
  56. * @param <T> 泛型标记
  57. * @return 响应信息 {@code Result}
  58. */
  59. public static <T> Result<T> success(@Nullable T data) {
  60. return new Result<>(ResultCode.SUCCESS, data);
  61. }
  62. }

一个用来深度学习并实战 spring boot 的项目,目前总共包含 66 个集成demo,已经完成 55 个。