public class JsonResponse<R> extends Object implements Serializable
Web controller json response
0.0.4:
Add method: successMessage and message; Change the name of the params field to otherData
1.0.5:
Move form framework web module to framework common module
1.0.9:
1.使用继承hashmap的方式
2.修改方法名
1.1.0:
1.修改方法名为 1.0.5 版本
2.Field: otherData 字段添加 final 修饰
3.Method: otherData 方法入参修改为 public JsonResponse<R> otherData(Map<String, ? extends Object> otherData)
| 构造器和说明 |
|---|
JsonResponse() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <R> JsonResponse<R> |
build()
Build a json response
|
JsonResponse<R> |
code(int code)
响应码
|
JsonResponse<R> |
data(R data)
响应数据
|
static <R> JsonResponse<R> |
failure()
失败响应
{
"code":500,
"status:false,
"message":"未知异常, 请联系管理员"
}
|
static <R> JsonResponse<R> |
failure(int code,
String message)
失败响应
|
static <R> JsonResponse<R> |
failure(String message)
失败响应
{
"code":500,
"status:false,
}
|
JsonResponse<R> |
message(String message)
响应消息
|
JsonResponse<R> |
otherData(Map<String,? extends Object> otherData)
响应其它数据
|
JsonResponse<R> |
otherData(String key,
Object value)
响应数据
|
static <R> JsonResponse<R> |
success()
成功响应
{
"code":0,
"status:true,
"message":"success"
}
|
static <R> JsonResponse<R> |
success(R data)
成功响应数据
|
static <R> JsonResponse<R> |
successMessage(String message)
成功响应消息
|
public static <R> JsonResponse<R> build()
R - 响应数据类型public static <R> JsonResponse<R> failure()
{
"code":500,
"status:false,
"message":"未知异常, 请联系管理员"
}
R - 响应数据类型public static <R> JsonResponse<R> failure(String message)
{
"code":500,
"status:false,
}
R - 响应数据类型message - 失败消息public static <R> JsonResponse<R> failure(int code, String message)
R - 响应数据类型code - 失败响应码message - 失败消息public static <R> JsonResponse<R> success()
{
"code":0,
"status:true,
"message":"success"
}
R - 响应数据类型public static <R> JsonResponse<R> success(R data)
R - 响应数据类型data - 数据public static <R> JsonResponse<R> successMessage(String message)
R - 响应数据类型message - 消息public JsonResponse<R> data(R data)
data - 数据public JsonResponse<R> otherData(Map<String,? extends Object> otherData)
otherData - 其它数据public JsonResponse<R> otherData(String key, Object value)
key - 数据键value - 数据值public JsonResponse<R> message(String message)
message - 消息public JsonResponse<R> code(int code)
code - 响应码Copyright © 2020. All rights reserved.