summaryrefslogtreecommitdiff
path: root/src/main/java/com/example/simpleminio/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/example/simpleminio/util')
-rw-r--r--src/main/java/com/example/simpleminio/util/R.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/main/java/com/example/simpleminio/util/R.java b/src/main/java/com/example/simpleminio/util/R.java
new file mode 100644
index 0000000..021ac1d
--- /dev/null
+++ b/src/main/java/com/example/simpleminio/util/R.java
@@ -0,0 +1,85 @@
+package com.example.simpleminio.util;
+
+import java.io.Serializable;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class R extends LinkedHashMap<String, Object> implements Serializable {
+ private static final long serialVersionUID = 1L;
+ public static final int CODE_SUCCESS = 200;
+ public static final int CODE_ERROR = 500;
+
+ public R(int code, String msg, Object data) {
+ this.setCode(code);
+ this.setMsg(msg);
+ this.setData(data);
+ }
+
+ public Integer getCode() {
+ return (Integer) this.get("code");
+ }
+
+ public String getMsg() {
+ return (String) this.get("msg");
+ }
+
+ public Object getData() {
+ return this.get("data");
+ }
+
+ public void setCode(int code) {
+ this.put("code", code);
+ }
+
+ public void setMsg(String msg) {
+ this.put("msg", msg);
+ }
+
+ public void setData(Object data) {
+ this.put("data", data);
+ }
+
+ public R set(String key, Object data) {
+ this.put(key, data);
+ return this;
+ }
+
+ public R setMap(Map<String, ?> map) {
+ for (String key : map.keySet()) {
+ this.put(key, map.get(key));
+ }
+ return this;
+ }
+
+ public static R ok() {
+ return new R(200, "ok", (Object) null);
+ }
+
+ public static R ok(String msg) {
+ return new R(200, msg, (Object) null);
+ }
+
+ public static R code(int code) {
+ return new R(code, (String) null, (Object) null);
+ }
+
+ public static R data(Object data) {
+ return new R(200, "ok", data);
+ }
+
+ public static R error() {
+ return new R(500, "error", (Object) null);
+ }
+
+ public static R error(String msg) {
+ return new R(500, msg, (Object) null);
+ }
+
+ public static R get(int code, String msg, Object data) {
+ return new R(code, msg, data);
+ }
+
+ public String toString() {
+ return "{\"code\": " + this.getCode() + ", \"msg\": \"" + this.getMsg() + "\", \"data\": \"" + this.getData() + "\"}";
+ }
+} \ No newline at end of file