首页>代码>基于SpringBoot+Vue实现的社区博客系统>/cxs-currency-sys-server-master/sys-common/src/main/java/com/cxs/base/BaseResult.java
package com.cxs.base; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.serializer.SerializerFeature; import com.cxs.constant.ResponseStateConstant; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.json.JSONObject; /* * @Project:cxs-currency-sys-server * @Author:cxs * @Motto:放下杂念,只为迎接明天更好的自己 * */ @ApiModel(value = "结果", description = "统一结果处理Bean") public class BaseResult<T> { @ApiModelProperty(value = "状态码") private Integer code; @ApiModelProperty(value = "信息") private String msg; @ApiModelProperty(value = "数据") @JSONField(serialzeFeatures = {SerializerFeature.WriteMapNullValue}) private T data; public BaseResult() { } public BaseResult(Integer code, String msg, T data) { this.code = code; this.msg = msg; this.data = data; } public Integer getCode() { return code; } public BaseResult setCode(Integer code) { this.code = code; return this; } public String getMsg() { return msg; } public BaseResult setMsg(String msg) { this.msg = msg; return this; } public T getData() { return data; } public BaseResult setData(T data) { this.data = data; return this; } /** * 操作成功 * * @return */ public static BaseResult ok() { BaseResult BaseResult = new BaseResult(); BaseResult.setMsg("操作成功"); BaseResult.setCode(ResponseStateConstant.OPERA_SUCCESS); BaseResult.setData(new JSONObject()); return BaseResult; } public static BaseResult ok(String msg) { BaseResult BaseResult = new BaseResult(); BaseResult.setCode(ResponseStateConstant.OPERA_SUCCESS); BaseResult.setData(new JSONObject()); BaseResult.setMsg(msg); return BaseResult; } /** * 操作失败 * * @return */ public static BaseResult error() { BaseResult BaseResult = new BaseResult(); BaseResult.setCode(ResponseStateConstant.OPERA_FAIL); BaseResult.setData(new JSONObject()); return BaseResult; } public static BaseResult error(String msg) { BaseResult BaseResult = new BaseResult(); BaseResult.setCode(ResponseStateConstant.OPERA_FAIL); BaseResult.setData(new JSONObject()); BaseResult.setMsg(msg); return BaseResult; } public Boolean resOk(){ return this.code == ResponseStateConstant.OPERA_SUCCESS; } @Override public String toString() { return "BaseResult{" + "code=" + code + ", msg='" + msg + '\'' + ", data=" + data + '}'; } }
最近下载更多
最近浏览更多
krispeng LV13
昨天
citybird LV4
11月18日
微信网友_6797029372219392 LV2
10月29日
wjs-zuizui
10月19日
暂无贡献等级
wlax99 LV12
10月12日
sgm123456 LV13
10月12日
半夏bx LV14
10月4日
zzzyyy1 LV2
10月4日
abdkfksdkf LV16
9月29日
15719908287 LV9
9月27日