/** * Copyright (c) 2016-2019 人人开源 All rights reserved. * * https://www.renren.io * * 版权所有,侵权必究! */ package com.peanut.common.utils; import lombok.Data; import lombok.experimental.Accessors; import org.apache.http.HttpStatus; import java.util.HashMap; import java.util.Map; /** * 返回数据 * * @author Mark sunlightcs@gmail.com */ @Data //@Accessors(chain = true) public class R extends HashMap { private static final long serialVersionUID = 1L; public R() { put("code", 0); put("msg", "success"); } public static R error() { // return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常,请联系管理员"); return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, ""); } public static R error(String msg) { return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg); } /** * int SC_NOT_IMPLEMENTED = 501; * int SC_BAD_GATEWAY = 502; * int SC_SERVICE_UNAVAILABLE = 503; * int SC_GATEWAY_TIMEOUT = 504; * @param * @param msg * @return */ public static R error1(String msg) { return error(HttpStatus.SC_NOT_IMPLEMENTED, msg); } public static R error2() { return error(HttpStatus.SC_BAD_GATEWAY,""); } public static R error3(String msg) { return error(HttpStatus.SC_SERVICE_UNAVAILABLE, msg); } public static R error4(String msg) { return error(HttpStatus.SC_GATEWAY_TIMEOUT, msg); } public static R error(int code, String msg) { R r = new R(); r.put("code", code); r.put("msg", msg); return r; } public static R code(int code){ R r = new R(); r.put("code",code); return r; } public static R code(int code,String msg){ R r = new R(); r.put("code",code); r.put("msg",msg); return r; } public static R ok(String msg) { R r = new R(); r.put("msg", msg); return r; } public static R ok(Map map) { R r = new R(); r.putAll(map); return r; } public static R ok() { return new R(); } public R put(String key, Object value) { super.put(key, value); return this; } }