WVPResult.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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> {
  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 <T> WVPResult<T> success(T t) {
  22. return success(t, ErrorCode.SUCCESS.getMsg());
  23. }
  24. public static <T> WVPResult<T> fail(int code, String msg) {
  25. return new WVPResult<>(code, msg, null);
  26. }
  27. public static <T> WVPResult<T> fail(ErrorCode errorCode) {
  28. return fail(errorCode.getCode(), errorCode.getMsg());
  29. }
  30. public int getCode() {
  31. return code;
  32. }
  33. public void setCode(int code) {
  34. this.code = code;
  35. }
  36. public String getMsg() {
  37. return msg;
  38. }
  39. public void setMsg(String msg) {
  40. this.msg = msg;
  41. }
  42. public T getData() {
  43. return data;
  44. }
  45. public void setData(T data) {
  46. this.data = data;
  47. }
  48. }