ResultUtils.java 907 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.example.onlinejudge.common;
  2. public class ResultUtils {
  3. /**
  4. * 成功
  5. *
  6. * @param data
  7. * @param <T>
  8. * @return
  9. */
  10. public static <T> BaseResponse<T> success(T data) {
  11. return new BaseResponse<>(0, data, "ok");
  12. }
  13. /**
  14. * 失败
  15. *
  16. * @param errorCode
  17. * @return
  18. */
  19. public static BaseResponse error(ErrorCode errorCode) {
  20. return new BaseResponse<>(errorCode);
  21. }
  22. /**
  23. * 失败
  24. *
  25. * @param code
  26. * @param message
  27. * @return
  28. */
  29. public static BaseResponse error(int code, String message) {
  30. return new BaseResponse(code, null, message);
  31. }
  32. /**
  33. * 失败
  34. *
  35. * @param errorCode
  36. * @return
  37. */
  38. public static BaseResponse error(ErrorCode errorCode, String message) {
  39. return new BaseResponse(errorCode.getCode(), null, message);
  40. }
  41. }