[TOC]
# **1. 启用注解**
`@GoEnableBody`
# **2. 状态码**
| 状态码 | 类型 |
| --- | --- |
| 0 | 成功 |
| -1 | 失败 |
| -2 | 异常 |
| -3 | 重试 |
# **3. 数据格式**
## **3.1 成功**
```
{"code":0,"msg":"操作成功","success":true,"data":{}}
```
## **3.2 失败**
```
{"code":-1,"msg":"操作失败","success":false}
```
## **3.3 异常**
```
{"code":-2,"msg":"操作异常","success":false}
```
## **3.4 重试**
```
{"code":-3,"msg":"重试失败","success":false}
```
# **4. 注意事项**
| 类别 | 类型 | 处理 |
| --- | --- | --- |
| Map | Java Map | 否× |
| Iterable | Java Iterable | 否× |
| String | Java String | 否× |
| Json | FastJson JSON| 否× |
| Result | FastBoot Result、PResult | 否× |
| Object | Java Object | 是✔ |
```
@RequestMapping("/xxx")
public Result getXXX() {
// 结果对象
// return R.succ();
// return R.succ(Object data)
// return R.succ(String msg)
// return R.succ(String msg, Object data)
// return R.succ(Integer code, String msg)
// return R.succ(Integer code, String msg, Object data)
// return R.fail();
// return .....
// return R.error();
// return .....
// 分页对象
// return PR.create(Page<?> page)
// return PR.create(List<?> data)
// return PR.create(List<?> data,Integer total)
}
```
> 排除 Map、Iterable、String、FastJson 、Result 不会处理外,其他Object均会统一格式返回,方法上添加注解@IgnoreBody可忽略处理
# **5. 示例说明**
## **5.1 Result**
```
@RequestMapping(value = "result")
public Result result() {
return R.succ(MockData.map());
}
```
```
{
"code": 0,
"msg": "操作成功",
"data": {
"k1": "1",
"k2": 2,
"k3": "3",
"k4": 4.1,
"k5": 5.2,
"k6": true,
"k7": "7",
"k8": "2021-06-17 16:44:50"
},
"status": true
}
```
> 由于本身已是统一结果对象,所以默认不会再次处理
## **5.2 Map**
```
@RequestMapping(value = "map")
public Map<String, Object> map() {
return MockData.map();
}
```
```
{
"k1": "1",
"k2": 2,
"k3": "3",
"k4": 4.1,
"k5": 5.2,
"k6": true,
"k7": "7",
"k8": "2021-06-17 16:58:53"
}
```
## **5.3 Iterable**
```
@RequestMapping(value = "list")
public List<String> list() {
return MockData.list();
}
```
```
[
"k1",
"k2",
"k3",
"k4",
"k5",
"k6",
"k7",
"k8"
]
```
## **5.4 String**
```
@RequestMapping(value = "string")
public String string() {
return MockData.fastjson().toString();
}
```
```
{
"k1": "1",
"k2": 2,
"k3": "3",
"k4": 4.1,
"k5": 5.2,
"k6": true,
"k7": "7",
"k8": "2021-06-17 16:57:17",
"list": [
"k1",
"k2",
"k3",
"k4",
"k5",
"k6",
"k7",
"k8"
]
}
```
## **5.5 Json**
```
@RequestMapping(value = "fastjson")
public JSON json() {
return MockData.fastjson();
}
```
```
{
"k1": "1",
"k2": 2,
"k3": "3",
"k4": 4.1,
"k5": 5.2,
"k6": true,
"k7": "7",
"k8": "2021-06-17 16:57:17",
"list": [
"k1",
"k2",
"k3",
"k4",
"k5",
"k6",
"k7",
"k8"
]
}
```
## **5.6 Object**
### **5.6.1 统一处理**
```
@RequestMapping(value = "object")
public MockUser object() {
return MockData.user();
}
```
```
{
"code": 0,
"msg": "操作成功",
"data": {
"name": "段正淳",
"birthDay": "2021-06-17 17:02:19",
"registerDay": "2021-06-17 17:02:19",
"idCard": "51343620000320711X",
"phone": "09127518479",
"tel": "13800138000",
"address": "xx市xx区xxxx街道xxx号",
"email": "123456789@qq.com",
"password": "a5sw7b65",
"carnumber": "京A88888",
"status": "A",
"enable": false
},
"status": true
}
```
### **5.6.2 忽略处理**
```
@IgnoreBody
@RequestMapping(value = "ignore")
public MockUser ignore() {
return MockData.user();
}
```
```
{
"name": "段正淳",
"birthDay": "2021-06-17 17:09:35",
"registerDay": "2021-06-17 17:09:35",
"idCard": "51343620000320711X",
"phone": "09127518479",
"tel": "13800138000",
"address": "xx市xx区xxxx街道xxx号",
"email": "123456789@qq.com",
"password": "f27btyhx",
"carnumber": "京A88888",
"status": "A",
"enable": false
}
```
### **5.6.3 脱敏处理**
```
@RequestMapping("/desensitized")
public MockDesensitized desensitized() {
return MockData.user2();
}
```
```
{
"code": 0,
"msg": "操作成功",
"data": {
"name": "段**",
"birthDay": "2021-06-17 17:12:07",
"registerDay": "2021-06-17",
"idCard": "5***************1X",
"phone": "0912*****79",
"tel": "138****8000",
"address": "xx市xx区xx********",
"email": "1********@qq.com",
"password": "********",
"carnumber": "京A8***8",
"status": "A",
"enable": false
},
"status": true
}
```
> 数据脱敏,利用了FastJson的特性,具体见`数据转换`章节