JsonResult.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.fdkankan.common.base;
  2. import com.alibaba.fastjson.JSON;
  3. import org.springframework.stereotype.Component;
  4. import java.util.Map;
  5. @Component("jsonResult")
  6. public class JsonResult {
  7. private String VERSION = Config.VERSION;
  8. private Integer statusCode;
  9. private String statusMsg;
  10. private String version;
  11. private String token;
  12. private Object data;
  13. public JsonResult() {
  14. this.setVersion(VERSION);
  15. }
  16. public Integer getStatusCode() {
  17. return statusCode;
  18. }
  19. public void setStatusCode(Integer statusCode) {
  20. this.statusCode = statusCode;
  21. }
  22. public String getStatusMsg() {
  23. return statusMsg;
  24. }
  25. public void setStatusMsg(String statusMsg) {
  26. this.statusMsg = statusMsg;
  27. }
  28. public String getVersion() {
  29. return version;
  30. }
  31. public void setVersion(String version) {
  32. this.version = version;
  33. }
  34. public String getToken() {
  35. return token;
  36. }
  37. public void setToken(String token) {
  38. this.token = token;
  39. }
  40. public Object getData() {
  41. return data;
  42. }
  43. public void setData(Object data) {
  44. this.data = data;
  45. }
  46. public String ok() {
  47. return this.ok("");
  48. }
  49. public String ok(Object data) {
  50. return this.ok("", data);
  51. }
  52. public String ok(String msg, Object data) {
  53. return this.base(200, msg, data);
  54. }
  55. public String parameterError(String msg, Map<String, Object> paramMap) {
  56. return this.base(203, msg, paramMap);
  57. }
  58. public String error(int code, String msg) {
  59. return this.error(code, msg, "");
  60. }
  61. public String error(int code, String msg, Object data) {
  62. return this.base(code, msg, data);
  63. }
  64. public String noRecord() {
  65. return this.base(202, "没有记录 !!!");
  66. }
  67. public String notLoggedIn() {
  68. return this.base(201, " 请登录 !!!");
  69. }
  70. public String notLoggedIn(Object data) {
  71. return this.base(201, " 请登录 !!!", data);
  72. }
  73. public String noPower() {
  74. return this.base(206, "没有权限!!!");
  75. }
  76. private String base(int code, String msg) {
  77. return this.base(code, msg, "");
  78. }
  79. private String base(int code, String msg, Object data) {
  80. JsonResult jd = new JsonResult();
  81. jd.setStatusCode(code);
  82. jd.setStatusMsg(msg);
  83. jd.setData(data);
  84. return JSON.toJSONString(jd);
  85. }
  86. }