ResponseDTO.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package net.lab1024.smartadmin.common.domain;
  2. import net.lab1024.smartadmin.common.constant.ResponseCodeConst;
  3. /**
  4. * 返回类
  5. *
  6. * @param <T>
  7. * @author zhuoda
  8. */
  9. public class ResponseDTO<T> {
  10. protected Integer code;
  11. protected String msg;
  12. protected Boolean success;
  13. protected T data;
  14. public ResponseDTO() {
  15. }
  16. public ResponseDTO(ResponseCodeConst responseCodeConst, String msg) {
  17. this.code = responseCodeConst.getCode();
  18. this.msg = msg;
  19. this.success = responseCodeConst.isSuccess();
  20. }
  21. public ResponseDTO(ResponseCodeConst responseCodeConst, T data) {
  22. super();
  23. this.code = responseCodeConst.getCode();
  24. this.msg = responseCodeConst.getMsg();
  25. this.data = data;
  26. this.success = responseCodeConst.isSuccess();
  27. }
  28. public ResponseDTO(ResponseCodeConst responseCodeConst, T data, String msg) {
  29. super();
  30. this.code = responseCodeConst.getCode();
  31. this.msg = msg;
  32. this.data = data;
  33. this.success = responseCodeConst.isSuccess();
  34. }
  35. private ResponseDTO(ResponseCodeConst responseCodeConst) {
  36. this.code = responseCodeConst.getCode();
  37. this.msg = responseCodeConst.getMsg();
  38. this.success = responseCodeConst.isSuccess();
  39. }
  40. public ResponseDTO(ResponseDTO responseDTO) {
  41. this.code = responseDTO.getCode();
  42. this.msg = responseDTO.getMsg();
  43. this.success = responseDTO.isSuccess();
  44. }
  45. public static <T> ResponseDTO<T> succ() {
  46. return new ResponseDTO(ResponseCodeConst.SUCCESS);
  47. }
  48. public static <T> ResponseDTO<T> succData(T data, String msg) {
  49. return new ResponseDTO(ResponseCodeConst.SUCCESS, data, msg);
  50. }
  51. public static <T> ResponseDTO<T> succData(T data) {
  52. return new ResponseDTO(ResponseCodeConst.SUCCESS, data);
  53. }
  54. public static <T> ResponseDTO succMsg(String msg) {
  55. return new ResponseDTO(ResponseCodeConst.SUCCESS, msg);
  56. }
  57. public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst) {
  58. return new ResponseDTO<>(codeConst);
  59. }
  60. public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst, T t) {
  61. return new ResponseDTO<T>(codeConst, t);
  62. }
  63. public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst, String msg) {
  64. return new ResponseDTO<T>(codeConst, msg);
  65. }
  66. public String getMsg() {
  67. return msg;
  68. }
  69. public ResponseDTO setMsg(String msg) {
  70. this.msg = msg;
  71. return this;
  72. }
  73. public int getCode() {
  74. return code;
  75. }
  76. public ResponseDTO setCode(Integer code) {
  77. this.code = code;
  78. return this;
  79. }
  80. public T getData() {
  81. return data;
  82. }
  83. public ResponseDTO setData(T data) {
  84. this.data = data;
  85. return this;
  86. }
  87. public boolean isSuccess() {
  88. return success;
  89. }
  90. public void setSuccess(boolean success) {
  91. this.success = success;
  92. }
  93. @Override
  94. public String toString() {
  95. return "ResponseDTO{" + "code=" + code + ", msg='" + msg + '\'' + ", success=" + success + ", data=" + data +
  96. '}';
  97. }
  98. }