标签:sage this ring err lse message int model 定义
1.定义返回码枚举
1 public interface ResultCode { 2 public static Integer SUCCESS = 20000; 3 public static Integer ERROR = 20001; 4 }
2. 创建结果类
1 @Data 2 public class R { 3 @ApiModelProperty(value = "是否成功") 4 private Boolean success; 5 @ApiModelProperty(value = "返回码") 6 private Integer code; 7 @ApiModelProperty(value = "返回消息") 8 private String message; 9 @ApiModelProperty(value = "返回数据") 10 private Map<String, Object> data = new HashMap<String, Object>(); 11 12 private R(){} 13 14 public static R ok(){ 15 R r = new R(); 16 r.setSuccess(true); 17 r.setCode(ResultCode.SUCCESS); 18 r.setMessage("成功"); 19 return r; 20 } 21 22 public static R error(){ 23 R r = new R(); 24 r.setSuccess(false); 25 r.setCode(ResultCode.ERROR); 26 r.setMessage("失败"); 27 return r; 28 } 29 30 public R success(Boolean success){ 31 this.setSuccess(success); 32 return this; 33 } 34 35 public R message(String message){ 36 this.setMessage(message); 37 return this; 38 } 39 40 public R code(Integer code){ 41 this.setCode(code); 42 return this; 43 } 44 45 public R data(String key, Object value){ 46 this.data.put(key, value); 47 return this; 48 } 49 50 public R data(Map<String, Object> map){ 51 this.setData(map); 52 return this; 53 } 54 55 }
标签:sage this ring err lse message int model 定义
原文地址:https://www.cnblogs.com/zhangshaui/p/15061923.html