1 @Data 2 public class ResultData implements Serializable { 3 4 /** 5 * 状态码 6 */ 7 private String code; 8 9 /** 10 * 提示信息 11 */ 12 private String msg; 13 14 /** 15 * 返回数据 16 */ 17 private Object data; 18 19 /** 20 * 接口调用的结果 true是成功。false是失败。 21 */ 22 private Boolean flag; 23 24 /** 25 * 结果记录数 26 */ 27 private Integer count; 28 29 public ResultData() { 30 } 31 32 public ResultData(String code, String msg, Object data, Integer count, Boolean flag) { 33 super(); 34 this.code = code; 35 this.msg = msg; 36 this.data = data; 37 this.count = count; 38 this.flag = flag; 39 } 40 41 /** 42 * 对返回值的封装 43 */ 44 45 public static ResultData success() { 46 return new ResultData(Constants.CODE_SUCCESS, Constants.MSG_SUCCESS, null, 0, true); 47 } 48 49 public static ResultData success(String msg) { 50 return new ResultData(Constants.CODE_SUCCESS, msg, null, 0, true); 51 } 52 53 public static ResultData success(String msg, Object data) { 54 return new ResultData(Constants.CODE_SUCCESS, msg, data, 0, true); 55 } 56 57 public static ResultData success(String msg, Object data, Integer count) { 58 return new ResultData(Constants.CODE_SUCCESS, msg, data, count, true); 59 } 60 61 public static ResultData success(String code, String msg, Object data, Integer count) { 62 return new ResultData(code, msg, data, count, true); 63 } 64 65 public static ResultData fail() { 66 return new ResultData(Constants.CODE_FAIL, Constants.MSG_FAIL, null, 0, false); 67 } 68 69 public static ResultData fail(String msg) { 70 return new ResultData(Constants.CODE_FAIL, msg, null, 0, false); 71 } 72 73 public static ResultData fail(String msg, Object data) { 74 return new ResultData(Constants.CODE_FAIL, msg, data, 0, false); 75 } 76 77 public static ResultData fail(String code, String msg, Object data) { 78 return new ResultData(code, msg, data, 0, false); 79 } 80 81 }
标签:封装,String,示例,ResultData,return,msg,Java,data,public From: https://www.cnblogs.com/Troy0912/p/16589651.html