cn.opencodes.vo.R Maven / Gradle / Ivy
The newest version!
package cn.opencodes.vo;
import java.util.HashMap;
import java.util.Map;
/**
* 返回数据
* @author HJ
*/
public class R {
private Object data;
private int code;
private String msg;
@SuppressWarnings("unchecked")
public R put(String key, Object value) {
if (data == null) {
data = new HashMap<>();
}
((Map)data).put(key, value);
return this;
}
public R put(Object value) {
data = value;
return this;
}
public static R ok(String msg) {
R r = new R();
r.msg = msg;
r.code = Const.HttpStatus.OK.value();
return r;
}
public static R ok() {
return R.ok("OK");
}
public static R failure(String msg) {
R r = new R();
r.code = Const.HttpStatus.FAILURE.value();
r.msg = msg;
return r;
}
public static R failure() {
return R.failure("failure");
}
public static R error(int code, String msg) {
R r = new R();
r.code = code;
r.msg = msg;
return r;
}
public static R error(String msg) {
return R.error(Const.HttpStatus.ERROR.value(), msg);
}
public static R error() {
return R.error("error");
}
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
public void setCode(int code) {
this.code = code;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}