目录

前端交互的结果集

# 前端交互的结果集

后端处理完数据后要将数据交给前端进行使用,但前后端必须在传递数据前达成统一标准用于接收和处理数据。因此,作为后端我们需要写一个统一的结果集,将结果存储在结果集中并返回

# 表现层数据封装

![[Pasted image 20220616111752.png]]

# 结果集设计

![[Pasted image 20220616111817.png]]

# 实现

为了实现上面两段的效果,我们需要写两个类分别是结果集Result和请求码ResultCode

Result 其实就一普通POJO类

public class Result {  
    private Object data;  
    private Integer code;  
    private String msg;  
  
    public Result(Object data, Integer code, String msg) {  
        this.data = data;  
        this.code = code;  
        this.msg = msg;  
    }  
  
    public Result(Object data, Integer code) {  
        this.data = data;  
        this.code = code;  
    }  
  
    public Result() {  
    }  
  
    public Object getData() {  
        return data;  
    }  
  
    public void setData(Object data) {  
        this.data = data;  
    }  
  
    public Integer getCode() {  
        return code;  
    }  
  
    public void setCode(Integer code) {  
        this.code = code;  
    }  
  
    public String getMsg() {  
        return msg;  
    }  
  
    public void setMsg(String msg) {  
        this.msg = msg;  
    }  
}
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

请求码

public class ResultCode {  
    public static final Integer SAVE_OK = 20011;  
    public static final int DELETE_OK = 20021;  
    public static final int UPDATE_OK = 20031;  
    public static final int GET_OK = 20041;  
  
    public static final Integer SAVE_ERR = 20010;  
    public static final int DELETE_ERR = 20020;  
    public static final int UPDATE_ERR = 20030;  
    public static final int GET_ERR = 20040;  
}
1
2
3
4
5
6
7
8
9
10
11
最近更新
01
基本知识
07-18
02
卷积神经网络识别图像
07-18
03
损失函数
07-18
更多文章>