2019-09-10 09:39:04 +08:00
|
|
|
|
关于list结构的返回json数据测试
|
|
|
|
|
|
|
|
|
|
# List<String>结构
|
|
|
|
|
|
|
|
|
|
api-doc对于List中返回基础数据类型都是支持的
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* List<String>
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "listString")
|
|
|
|
|
public List<String> testList() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
api-doc生成的响应数据
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
[ "ivvqah","isrz5x"]
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
# List<Map<String,String>>结构
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/map/Primitive")
|
|
|
|
|
public List<Map<String,String>> testMap() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
api-doc生成的响应数据
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
[{
|
|
|
|
|
"mapKey1": "o9mibj",
|
|
|
|
|
"mapKey2": "3dnnrn"
|
|
|
|
|
}]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# List<Map<String,T>>结构
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
@GetMapping(value = "/map/Primitive")
|
|
|
|
|
public List<Map<String,Student>> testMap() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
相应数据省略
|
|
|
|
|
|
|
|
|
|
# 测试List<T>结构
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* 测试List<T>结构
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/map/Primitive")
|
|
|
|
|
public List<Teacher> testMap() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# List<T<M,N>>结构
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* 测试List<T<M,N>>结构
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/map/Primitive")
|
|
|
|
|
public List<Teacher<User,User>> testMap() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
# List<Map<M,N<P,k>>>超复杂结构
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* 测试List<Map<M,N<P,k>>>超复杂结构
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/map/Primitive")
|
|
|
|
|
public List<Map<String,Teacher<User,User>>> testMap() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
api-doc自动返回的数据
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
[{
|
|
|
|
|
"mapKey": {
|
|
|
|
|
"data": {
|
|
|
|
|
"userName": "lxh2yi",
|
|
|
|
|
"userAddress": "6jfp3h",
|
|
|
|
|
"userAge": 741
|
|
|
|
|
},
|
|
|
|
|
"data1": {
|
|
|
|
|
"userName": "1wp54g",
|
|
|
|
|
"userAddress": "8ul6m4",
|
|
|
|
|
"userAge": 550
|
|
|
|
|
},
|
|
|
|
|
"age": 10
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
# List<T<List<M>,List<M>,List<M>>>超复杂结构
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* List<T<List<M>,List<M>,List<M>>>
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "listString")
|
|
|
|
|
public List<Teacher<List<User>,List<User>,List<User>>> testListString(){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
# 其他复杂结构
|
2021-05-16 12:02:05 +08:00
|
|
|
|
|
2019-09-10 09:39:04 +08:00
|
|
|
|
```
|
|
|
|
|
/**
|
|
|
|
|
* List<T<List<M>,List<M>,List<M>>>
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "listString")
|
|
|
|
|
public List<Teacher<Teacher<User,User,User>,User,User>> testListString() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "listString")
|
|
|
|
|
public List<Teacher<Teacher<User,User,User>,Teacher<User,User,User>,Teacher<User,User,User>>> testListString() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-05-16 12:02:05 +08:00
|
|
|
|
**注意:** api-doc为了传入的复杂泛型结构数据,做了许多情况的测试,目前基本能兼容系统开发中95%以上的List返回接口, 也提供了一些能够处理的很复杂的泛型结构,但是这种复杂的泛型结构在开发中是不被推荐的。
|