ResultMsg.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.gyee.power.fitting.common.config;
  2. import lombok.Data;
  3. /**
  4. * @ClassName : R
  5. * @Author : xieshengjie
  6. * @Date: 2021/5/16 16:59
  7. * @Description : 结果集
  8. */
  9. @Data
  10. public class ResultMsg {
  11. //@ApiModelProperty(value = "是否成功")
  12. private Boolean success;
  13. //@ApiModelProperty(value = "返回码")
  14. private Integer code;
  15. //@ApiModelProperty(value = "返回消息")
  16. private String message;
  17. //@ApiModelProperty(value = "总数量")
  18. private Integer count;
  19. //@ApiModelProperty(value = "返回数据")
  20. private Object data = new Object();
  21. public ResultMsg(){}
  22. public static ResultMsg ok(){
  23. ResultMsg r = new ResultMsg();
  24. r.setSuccess(true);
  25. r.setCode(ResultCode.SUCCESS);
  26. r.setMessage("成功");
  27. return r;
  28. }
  29. public static ResultMsg ok(Object data ){
  30. ResultMsg r = new ResultMsg();
  31. r.setSuccess(true);
  32. r.setCode(ResultCode.SUCCESS);
  33. r.setData(data);
  34. r.setMessage("成功");
  35. return r;
  36. }
  37. public static ResultMsg ok(Object data,Integer count ){
  38. ResultMsg r = new ResultMsg();
  39. r.setSuccess(true);
  40. r.setCode(ResultCode.SUCCESS);
  41. r.setData(data);
  42. r.setMessage("成功");
  43. r.setCount(count);
  44. return r;
  45. }
  46. public static ResultMsg ok(Integer count){
  47. ResultMsg r = new ResultMsg();
  48. r.setSuccess(true);
  49. r.setCode(ResultCode.SUCCESS);
  50. r.setMessage("成功");
  51. r.setCount(count);
  52. return r;
  53. }
  54. public static ResultMsg error(){
  55. ResultMsg r = new ResultMsg();
  56. r.setSuccess(false);
  57. r.setCode(ResultCode.ERROR);
  58. r.setMessage("失败");
  59. return r;
  60. }
  61. public ResultMsg success(Boolean success){
  62. this.setSuccess(success);
  63. return this;
  64. }
  65. public ResultMsg message(String message){
  66. this.setMessage(message);
  67. return this;
  68. }
  69. public static ResultMsg errorMsg(String msg){
  70. ResultMsg r = new ResultMsg();
  71. r.setSuccess(false);
  72. r.setCode(ResultCode.ERROR);
  73. r.setMessage(msg);
  74. return r;
  75. }
  76. public ResultMsg code(Integer code){
  77. this.setCode(code);
  78. return this;
  79. }
  80. public ResultMsg data(Object value){
  81. this.setData(value);
  82. return this;
  83. }
  84. }