Web响应

public class R1 extends HashMap<String, Object> {

private static final long serialVersionUID = 1L;
public R1() {
put("code", 0);
put("msg", "success");
}
public Integer getCode(){
Object code = get("code");
String s = String.valueOf(code);
return Integer.valueOf(s);
}
public <T> T getData(String key, TypeReference<T> tTypeReference){
Object data = this.get(key);
String s = JSON.toJSONString(data);
T t = JSON.parseObject(s, tTypeReference);
return t;
}

public static R1 error(int code, String msg) {
R1 r = new R1();
r.put("code", code);
r.put("msg", msg);
return r;
}
public static R1 ok() {
return new R1();
}

public R1 put(String key, Object value) {
super.put(key, value);
return this;
}
}
posted @ 2021-10-13 22:45  一只大冬瓜  阅读(44)  评论(0)    收藏  举报