我是靠谱客的博主 标致小甜瓜,最近开发中收集的这篇文章主要介绍java后端返回统一报文类,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

package com.czqc.czc.buz.api.beans.vo;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
public class ResponseStatus<T> implements Serializable {
@ApiModelProperty("报文状态: 0 失败,1 成功,-1 未登录,-2 无权限")
private Integer status = 1;
@ApiModelProperty("报文: 成功响应报文,失败响应错误信息")
private T msg = (T) "ok";
public static ResponseStatus ok() {
return new ResponseStatus();
}
public static ResponseStatus list(Integer totalPages, Object content) {
return new ResponseStatus(totalPages, content);
}
public static ResponseStatus object(Object content) {
return new ResponseStatus(content);
}
public static ResponseStatus exception(Integer status, String errMsg) {
return new ResponseStatus(status, errMsg);
}
public ResponseStatus(T content) {
this.msg = content;
}
public ResponseStatus(Integer totalPages, T content) {
ResponseMsgVO<T> responseMsgVO = new ResponseMsgVO<>();
responseMsgVO.setTotalPages(totalPages);
responseMsgVO.setContent(content);
this.msg = (T) responseMsgVO;
}
public ResponseStatus(Integer status, String msg) {
this.status = status;
this.msg = (T) msg;
}
public ResponseStatus() {
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public T getMsg() {
return msg;
}
public void setMsg(T msg) {
this.msg = msg;
}
@Override
public String toString() {
return "MsgStatus{" +
"status=" + status +
", msg=" + msg +
'}';
}
public static class ResponseMsgVO<T> implements
Serializable {
@ApiModelProperty("总页数")
private Integer totalPages = 0;
@ApiModelProperty("内容")
private T content = (T) "ok";
public ResponseMsgVO(Integer totalPages, T content) {
this.totalPages = totalPages;
this.content = content;
}
public ResponseMsgVO(T content) {
this.content = content;
}
public ResponseMsgVO() {
}
public Integer getTotalPages() {
return totalPages;
}
public void setTotalPages(Integer totalPages) {
this.totalPages = totalPages;
}
public T getContent() {
return content;
}
public void setContent(T content) {
this.content = content;
}
@Override
public String toString() {
return "ResponseMsg0VO{" +
"totalPages=" + totalPages +
", content=" + content +
'}';
}
}
}

最后

以上就是标致小甜瓜为你收集整理的java后端返回统一报文类的全部内容,希望文章能够帮你解决java后端返回统一报文类所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部