master
管理员 3 years ago
parent 3b6aefe8ca
commit 86c412ee40

@ -5,6 +5,10 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* *
@ -32,6 +36,21 @@ public class R<T> implements Serializable {
private T data; private T data;
public R<T> setCode(int code){
this.code = code;
return this;
}
public R<T> setMsg(String msg){
this.msg = msg;
return this;
}
public R<T> setData(T data) {
this.data = data;
return this;
}
public static <T> R<T> ok() { public static <T> R<T> ok() {
return restResult(null, SUCCESS, "操作成功"); return restResult(null, SUCCESS, "操作成功");
} }
@ -104,4 +123,36 @@ public class R<T> implements Serializable {
public static <T> Boolean isSuccess(R<T> ret) { public static <T> Boolean isSuccess(R<T> ret) {
return R.SUCCESS == ret.getCode(); return R.SUCCESS == ret.getCode();
} }
public static R<Map<String, ?>> map(){
R<Map<String, ?>> r = new R<>();
r.setData(new HashMap<>());
return r;
}
@SuppressWarnings("unchecked")
public R<Map<String, ?>> put(String key,Object value){
if(this.data instanceof Map) {
((Map<String,Object>)this.data).put(key, value);
return (R<Map<String, ?>>) this;
}else {
throw new RuntimeException("data does not belong to Map");
}
}
public static R<List<?>> list(){
R<List<?>> r = new R<>();
r.setData(new ArrayList<>());
return r;
}
@SuppressWarnings("unchecked")
public R<List<?>> add(Object value){
if(this.data instanceof List) {
((List<Object>)this.data).add(value);
return (R<List<?>>) this;
}else {
throw new RuntimeException("data does not belong to List");
}
}
} }

Loading…
Cancel
Save