当前位置:网站首页>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
}
}

边栏推荐
猜你喜欢

Operation and use of collection framework

【idea插件神器】教你如何使用IDEA一键set实体类中所有属性

集合框架的操作使用

论文写作用词

Tomato timing dimming table lamp touch chip-dlt8t10s-jericho

使用navicat或plsql导出csv格式,超过15位数字后面变成000(E+19)的问题

Distillation model diagram

架构设计思考之一(SSO设计)

Advanced multithreading: the role and implementation principle of volatile

蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题
随机推荐
蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题
You must configure either the server or JDBC driver (via the ‘serverTimezone)
JVM notes 3: class loading and bytecode Technology
The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem
Distillation model diagram
深度学习热力图可视化的方式
BigDecimal 进行四舍五入 四舍六入和保留两位小数
ByteBuffer.position 抛出异常 IllegalArgumentException
【idea插件神器】教你如何使用IDEA一键set实体类中所有属性
CentOS7安装MySQL5.7
Openjudge: upper and lower case letters are interchanged
MySQL adds sequence number to query results
Response<T>类
IDEA配置 service(Run Dashboard) 服务,多模块同时启动
解决Oracle使用in语句不能超过1000问题
子父线程交互
IDEA使用dev-tool实现热部署
ssm项目快速搭建项目配置文件
openjudge:矩阵乘法
JVM note 4: Memory Model