|
|
|
|
@ -5,6 +5,10 @@ import lombok.Data;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
return restResult(null, SUCCESS, "操作成功");
|
|
|
|
|
}
|
|
|
|
|
@ -104,4 +123,36 @@ public class R<T> implements Serializable {
|
|
|
|
|
public static <T> Boolean isSuccess(R<T> ret) {
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|