当前位置:网站首页>Custom JSON return data
Custom JSON return data
2022-07-28 05:39:00 【jekyhu】
- Back end development , Use spring The official return data agreement is not unified ⼀, Missing business status code .
- Thus, you can define the status code by yourself , Achieve unity with the front end .
public class JsonData {
private int code;
private Object data;
private String msg;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public JsonData(){}
public JsonData(int code, Object data){
this.code = code;
this.data = data;
}
public JsonData(int code, Object data, String msg){
this.code = code;
this.data =data;
this.msg = msg;
}
public static JsonData buildSuccess(Object data){
return new JsonData(1,data);//1 On behalf of success
}
public static JsonData buildError(String msg){
return new JsonData(0,"",msg);//0 For failure
}
public static JsonData buildError(String msg,int code){
return new JsonData(code,"",msg);// Custom status code , Unified with the front end
}
}

边栏推荐
- 科研论文写作方法:在方法部分添加分析和讨论说明自己的贡献和不同
- How to compare long and integer and why to report errors
- Multi module packaging: package: XXX does not exist
- Openjudge: upper and lower case letters are interchanged
- 冶金物理化学复习 --- 气-液相反应动力学
- Edge calculation kubeedge+edgemash
- How Visio accurately controls the size, position and angle of graphics
- Low illumination image data set
- When using \hl for highlighting, latex always reports an error when encountering a reference, showing that there are fewer or more parentheses
- Tomato timing dimming table lamp touch chip-dlt8t10s-jericho
猜你喜欢

MySQL adds sequence number to query results

The difference between get and post

蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题

框架一步一步方便使用的流程

冶金物理化学复习 --- 复杂反应的速率方程

Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions

FusionGAN代码学习(一)

Thinking on multi system architecture design

IDEA配置 service(Run Dashboard) 服务,多模块同时启动

蒸馏模型图
随机推荐
About localdatetime in swagger
restFul接口使用个人总结
mybaties foreach多选查询,index循环,取消and/or标签
Redis 之布隆过滤器
Long和Integer如何进行比较,为什么报错
冶金物理化学复习 --- 气-液相反应动力学
regular expression
多线程进阶:synchronized底层原理,锁优化、锁升级的过程
docker 部署 mysql5.7.35
解决Oracle使用in语句不能超过1000问题
项目中问题合集
Mabtis(一)框架的基本使用
yandex robots txt
Oracle创建表、删除表、修改表(添加字段、修改字段、删除字段)语句总结
When using \hl for highlighting, latex always reports an error when encountering a reference, showing that there are fewer or more parentheses
ECCV22 最新54篇论文主图整理
【MySQL】MySQL时区问题、数据库时间相差8小时问题解决
Problems encountered when the registry service Eureka switches to nocas
Openjudge: count the number of numeric characters
IO流的使用