统一响应结果封装类
| 4 | * 统一响应结果封装类 |
| 5 | */ |
| 6 | public class Result { |
| 7 | private Integer code; //0 成功 1失败 |
| 8 | private String msg; //提示信息 |
| 9 | private Object data; //数据 data |
| 10 | |
| 11 | public Result() { |
| 12 | } |
| 13 | |
| 14 | public Result(Integer code, String msg, Object data) { |
| 15 | this.code = code; |
| 16 | this.msg = msg; |
| 17 | this.data = data; |
| 18 | } |
| 19 | |
| 20 | public Integer getCode() { |
| 21 | return code; |
| 22 | } |
| 23 | |
| 24 | public void setCode(Integer code) { |
| 25 | this.code = code; |
| 26 | } |
| 27 | |
| 28 | public String getMsg() { |
| 29 | return msg; |
| 30 | } |
| 31 | |
| 32 | public void setMsg(String msg) { |
| 33 | this.msg = msg; |
| 34 | } |
| 35 | |
| 36 | public Object getData() { |
| 37 | return data; |
| 38 | } |
| 39 | |
| 40 | public void setData(Object data) { |
| 41 | this.data = data; |
| 42 | } |
| 43 | |
| 44 | // 用于返回增删改操作成功的结果 |
| 45 | public static Result success(Object data){ |
| 46 | return new Result(0,"success", data); |
| 47 | } |
| 48 | |
| 49 | // 用于返回查询操作成功的结果 |
| 50 | public static Result success(){ |
| 51 | return new Result(0,"success", null); |
| 52 | } |
| 53 | |
| 54 | // 用于返回操作失败的结果 |
| 55 | public static Result error(Object data){ |
| 56 | return new Result(1,"error", data); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public String toString() { |
| 61 | return "Result{" + |
| 62 | "code=" + code + |
| 63 | ", msg='" + msg + '\'' + |
nothing calls this directly
no outgoing calls
no test coverage detected