1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| import io.swagger.annotations.ApiModelProperty; import lombok.Data;
import java.util.HashMap; import java.util.Map;
@Data public class R { @ApiModelProperty(value = "是否成功") private Boolean success;
@ApiModelProperty(value = "返回码") private Integer code;
@ApiModelProperty(value = "返回消息") private String message;
@ApiModelProperty(value = "返回数据") private Map<String, Object> data = new HashMap<String, Object>();
private R() { }
public static R ok() { R r = new R(); r.setSuccess(true); r.setCode(ResultCode.SUCCESS); r.setMessage("成功"); return r; } public static R error() { R r = new R(); r.setSuccess(false); r.setCode(ResultCode.ERROR); return r; }
public static R res() { R r = new R(); r.setSuccess(false); r.setCode(ResultCode.RES); r.setMessage("该手机号已注册"); return r; }
public static R end() { R r = new R(); r.setSuccess(false); r.setCode(ResultCode.END); r.setMessage("over"); return r; }
public static R share(Integer type) { R r = new R(); r.setSuccess(false); r.setCode(type); return r; }
public R success(Boolean success) { this.setSuccess(success); return this; }
public R message(String message) { this.setMessage(message); return this; }
public R code(Integer code) { this.setCode(code); return this; }
public R data(String key, Object value) { this.data.put(key, value); return this; }
public R data(Map<String, Object> map) { this.setData(map); return this; } }
|