Java-封装结果集示例
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 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库