import java.util.HashMap;
public class ResponseBo extends HashMap<String, Object> {
private static final long serialVersionUID = -8713837118340960775L;
// 成功
private static final Integer SUCCESS = 0;
// 警告
private static final Integer WARN = 1;
// 异常 失败
private static final Integer FAIL = 500;
public ResponseBo() {
put("code", SUCCESS);
put("data", "操作成功");
}
public static ResponseBo error(Object data) {
ResponseBo responseBo = new ResponseBo();
responseBo.put("code", FAIL);
responseBo.put("data", data);
return responseBo;
}
public static ResponseBo warn(Object data) {
ResponseBo responseBo = new ResponseBo();
responseBo.put("code", WARN);
responseBo.put("data", data);
return responseBo;
}
public static ResponseBo ok(Object data) {
ResponseBo responseBo = new ResponseBo();
responseBo.put("code", SUCCESS);
responseBo.put("data", data);
return responseBo;
}
public static ResponseBo ok() {
return new ResponseBo();
}
public static ResponseBo error() {
return ResponseBo.error("");
}
@Override
public ResponseBo put(String key, Object value) {
super.put(key, value);
return this;
}
}
自定义接口响应格式ResponseBo
最新推荐文章于 2024-01-11 10:08:43 发布