Result.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package zs.payment.resp;
  2. import com.alibaba.fastjson.annotation.JSONField;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. /**
  6. * 统一响应封装
  7. */
  8. public class Result {
  9. @JSONField(name = "body")
  10. private Map<String, Object> body;
  11. private Result(Map<String, Object> body) {
  12. this.body = body;
  13. }
  14. public static Result success() {
  15. Map<String, Object> body = new HashMap<>();
  16. body.put("CODE", 200);
  17. body.put("MSG", "SUCCESS");
  18. return new Result(body);
  19. }
  20. // public static Result success(String token) {
  21. // Map<String, Object> body = new HashMap<>();
  22. // body.put("CODE", 200);
  23. // body.put("MSG", "SUCCESS");
  24. // body.put("token", token);
  25. // return new Result(body);
  26. // }
  27. public static Result success(Object data) {
  28. Map<String, Object> body = new HashMap<>();
  29. body.put("CODE", 200);
  30. body.put("MSG", "SUCCESS");
  31. body.put("data", data);
  32. return new Result(body);
  33. }
  34. public static Result fail(String msg) {
  35. Map<String, Object> body = new HashMap<>();
  36. body.put("CODE", 500);
  37. body.put("MSG", msg);
  38. return new Result(body);
  39. }
  40. public Map<String, Object> getBody() {
  41. return body;
  42. }
  43. public boolean isSuccess() {
  44. return Integer.valueOf(200).equals(body.get("CODE"));
  45. }
  46. }