WVPResult.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package com.genersoft.iot.vmp.vmanager.bean;
  2. import io.swagger.v3.oas.annotations.media.Schema;
  3. @Schema(description = "统一返回结果")
  4. public class WVPResult<T> implements Cloneable{
  5. public WVPResult() {
  6. }
  7. public WVPResult(int code, String msg, T data) {
  8. this.code = code;
  9. this.msg = msg;
  10. this.data = data;
  11. }
  12. @Schema(description = "错误码,0为成功")
  13. private int code;
  14. @Schema(description = "描述,错误时描述错误原因")
  15. private String msg;
  16. @Schema(description = "数据")
  17. private T data;
  18. public static <T> WVPResult<T> success(T t, String msg) {
  19. return new WVPResult<>(ErrorCode.SUCCESS.getCode(), msg, t);
  20. }
  21. public static WVPResult success() {
  22. return new WVPResult<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), null);
  23. }
  24. public static <T> WVPResult<T> success(T t) {
  25. return success(t, ErrorCode.SUCCESS.getMsg());
  26. }
  27. public static <T> WVPResult<T> fail(int code, String msg) {
  28. return new WVPResult<>(code, msg, null);
  29. }
  30. public static <T> WVPResult<T> fail(ErrorCode errorCode) {
  31. return fail(errorCode.getCode(), errorCode.getMsg());
  32. }
  33. public int getCode() {
  34. return code;
  35. }
  36. public void setCode(int code) {
  37. this.code = code;
  38. }
  39. public String getMsg() {
  40. return msg;
  41. }
  42. public void setMsg(String msg) {
  43. this.msg = msg;
  44. }
  45. public T getData() {
  46. return data;
  47. }
  48. public void setData(T data) {
  49. this.data = data;
  50. }
  51. @Override
  52. public Object clone() throws CloneNotSupportedException {
  53. return super.clone();
  54. }
  55. }