# 请求响应消息
# 配置说明
application.yml
qmframework:
# ※※※※※※※※※通讯配置※※※※※※※※※
transmit:
# 请求数据时,最外层的key名(rest风格)
request-key: 'value'
# 返回数据时,最外层的key名(rest风格)
response-key: 'value'
# 返回数据时,默认message的语言 EN/CN
response-message-lang: CN
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 请求格式
{
"value":{
// ... 请求数据
}
}
1
2
3
4
5
2
3
4
5
如果设置了body.request.key则按照设置的值作为key,否则没有最外层key
# 返回格式
{
"value":{
"msg":"Success",
"code":1,
"data":{
// ... 返回数据
}
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
如果设置了body.response.key则按照设置的值作为key,否则使用
value
# 服务端状态码规范
状态码 | 说明 |
---|---|
1~99 | 业务编码,在书写业务时常用该范围编码 |
100~199 | 全局编码,应用全局返回时使用该范围编码 |
400~499 | 访问编码,应用全局访问时出现异常使用该范围编码 |
500~999 | 服务器异常编码,应用全局服务器异常时使用该范围编码 |
# 状态码枚举类源码
在调用
QmResult
时,类中已经定义好常用的状态类型,如果需要自定义,调用QmResult.sendJson(QmCode._xxx, msg, data);
QmCode
枚举封装了我们规定的一套状态码规范。具体源码如下:
public enum QmCode {
/**
* 成功
*/
_1(1, "操作成功", "Success"),
/**
* 失败
*/
_2(2, "操作失败", "Defeated"),
/**
* 参数提供不完整
*/
_100(100, "参数提供不完整", "Parameter is incomplete"),
/**
* 参数错误
*/
_101(101, "参数错误", "Parameter error"),
/**
* 版本号未通过
*/
_102(102, "未通过版本校验", "Version validation failed"),
/**
* 未登录/登录过期/请求ip校验失败
*/
_103(103, "登录状态已失效", "Login not in"),
/**
* 权限不足,拒绝访问
*/
_104(104, "无访问权限", "Permission denied"),
/**
* 您的账号已在其他地方登录!
*/
_105(105,"您的账号已在其他地方登录!","Your account has been logged in elsewhere"),
/**
* 请求404,找不到资源
*/
_404(404, "资源丢失啦", "Can't find resources"),
/**
* 请求405,请求类型错误POST or GET
*/
_405(405, "请求方式错误", "Wrong request mode"),
/**
* 请求415,不支持的媒体类型
*/
_415(415, "不支持的媒体类型", "Unsupported media types"),
/**
* 服务器错误
*/
_500(500, "服务器开小差啦", "Server Error"),
/**
* 未知错误
*/
_999(999, "未知错误", "Server unknow");
/**
* 编码
*/
private int code;
/**
* 中文msg
*/
private String cnMsg;
/**
* 英文msg
*/
private String enMsg;
private QmCode(int code, String cnMsg, String enMsg) {
this.code = code;
this.cnMsg = cnMsg;
this.enMsg = enMsg;
}
public int getCode() {
return code;
}
/**
* 根据code获取对应msg信息
*
* @param code
* @return msg
*/
public static final String getMsg(QmCode code) {
return "cn".equalsIgnoreCase(TransmitConfiguration.responseMessageLang) ? code.cnMsg : code.enMsg;
}
}
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
← Controller AES 双向对称加密 →