浏览代码

增加返回实体

dos 8 月之前
父节点
当前提交
a8d822137e

+ 93 - 0
game-common/src/main/java/com/game/common/core/domain/HttpRet.java

@@ -0,0 +1,93 @@
+package com.game.common.core.domain;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+
+
+@ApiModel(value = "HttpRet", description = "HttpRet")
+@Data
+public class HttpRet<T> implements Serializable {
+
+	/**
+	 * 如果只返回简单类型T用 SingleString
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public static final int SUCCESS = 1;
+
+	public static final int FAIL = 2;
+
+	//@ApiModelProperty(value = "error")
+    //public int error=0;
+
+    //@ApiModelProperty(value = "url")
+    //public String url;
+
+	@ApiModelProperty(value = "1=成功;44001=网络错误或服务器返回异常;44002=json解析或转model异常;44003=token失效了;44006=系统关闭中;44009=游客不能使用此功能", name = "code")
+	public int code;
+
+	@ApiModelProperty(value = "返回的消息", name = "msg")
+	public String msg;
+
+	@ApiModelProperty(value = "返回实体", name = "retObj")
+	public T retObj;
+
+	//为了ApiCacheRet 接口保留的
+	public String retStr;
+
+
+	public HttpRet(int code, String msg, T retObj) {
+		this.code = code;
+		this.msg = msg;
+		this.retObj = retObj;
+	}
+/*
+	public HttpRet(String url,int error, T retObj) {
+		this.error = code;
+		this.url = url;
+		this.retObj = retObj;
+	}
+*/
+	//
+	public static <T> HttpRet<T> genResult(int code, String msg, T retObj) {
+		HttpRet<T> result = new HttpRet<T>(code, msg, retObj);
+		return result;
+	}
+/*
+	public static <T> HttpRet<T> genResultFileDto(String url,int error, T retObj) {
+		HttpRet<T> result = new HttpRet<T>(url,error,  retObj);
+		return result;
+	}
+*/
+
+	public static <T> HttpRet<T> success(String msg, T data) {
+		return genResult(1, msg, data);
+	}
+/*
+	public static <T> HttpRet<T> successFileDto(String url, T data) {
+		return genResultFileDto(url,0,  data);
+	}
+*/
+
+	public static <T> HttpRet<T> success(String msg) {
+		return genResult(1, msg, null);
+	}
+
+	public static <T> HttpRet<T> fail(String message) {
+		return genResult(2, message, null);
+	}
+
+	public static <T> HttpRet<T> fail(int code, String message) {
+		return genResult(code, message, null);
+	}
+
+	@Override
+	public String toString() {
+		return "RestResult{" + "code=" + code + ", msg='" + msg + '\'' + ", retObj=" + retObj + '}';
+	}
+
+}

+ 63 - 0
game-common/src/main/java/com/game/common/core/domain/HttpRetArr.java

@@ -0,0 +1,63 @@
+package com.game.common.core.domain;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@ApiModel(value = "HttpRetArr", description = "HttpRetArr")
+@Data
+public class HttpRetArr<T> implements Serializable {
+
+	/**
+	 *
+	 */
+	private static final long serialVersionUID = 1L;
+
+	@ApiModelProperty(value = "44001=网络错误或服务器返回异常;44002=json解析或转model异常;44003=token失效了;44006=系统关闭中;", name = "code")
+	public int code;
+
+	@ApiModelProperty(value = "返回的消息", name = "msg")
+	public String msg;
+
+	@ApiModelProperty(value = "返回实体列表", name = "retArr")
+	public List<T> retArr;
+
+	//为了ApiCacheRet 接口保留的
+	public String retStr;
+
+
+	public HttpRetArr(int code, String msg, List<T> retObj) {
+		this.code = code;
+		this.msg = msg;
+		this.retArr = retObj;
+	}
+
+	public static <T> HttpRetArr<T> genResult(int code, String msg, List<T> retObj) {
+		HttpRetArr<T> result = new HttpRetArr<T>(code, msg, retObj);
+		return result;
+	}
+
+	public static <T> HttpRetArr<T> success(String msg, List<T> data) {
+		return genResult(1, msg, data);
+	}
+
+	public static <T> HttpRetArr<T> success(String msg) {
+		return genResult(1, msg, null);
+	}
+
+	public static <T> HttpRetArr<T> fail(String message) {
+		return genResult(2, message, null);
+	}
+
+	public static <T> HttpRetArr<T> fail(int code, String message) {
+		return genResult(code, message, null);
+	}
+
+	@Override
+	public String toString() {
+		return "HttpRetArr{" + "code=" + code + ", msg='" + msg + '\'' + ", retArr=" + retArr + '}';
+	}
+}

+ 109 - 0
game-common/src/main/java/com/game/common/core/domain/HttpRetPageArr.java

@@ -0,0 +1,109 @@
+package com.game.common.core.domain;
+
+import com.game.common.core.page.TableDataInfo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@ApiModel(value = "HttpRetPageArr", description = "HttpRetPageArr")
+@Data
+public class HttpRetPageArr<T> implements Serializable {
+
+	/**
+	 *
+	 */
+	private static final long serialVersionUID = 1L;
+
+	@ApiModelProperty(value = "44001=网络错误或服务器返回异常;44002=json解析或转model异常;44003=token失效了;44006=系统关闭中;", name = "code")
+	public int code;
+
+	@ApiModelProperty(value = "返回的消息", name = "msg")
+	public String msg;
+
+	/*
+	 * 每页查询多少条
+	 */
+	@ApiModelProperty(value = "每页条数", name = "pageSize")
+	public int pageSize;
+
+	/*
+	 * 查询第几页
+	 */
+	@ApiModelProperty(value = "当前页数", name = "pageIndex")
+	public int pageIndex;
+
+	/*
+	 * 返回数据,总共有多少页
+	 */
+	@ApiModelProperty(value = "总页数", name = "outTotalPage")
+	public int outTotalPage;
+
+	/*
+	 * 返回数据,总共有多少条记录
+	 */
+	@ApiModelProperty(value = "总条数", name = "outTotalCount")
+	public int outTotalCount;
+
+	@ApiModelProperty(value = "返回实体列表", name = "retArr")
+	public List<T> retArr;
+
+	//为了ApiCacheRet 接口保留的
+	public String retStr;
+
+	
+	public void setPageInfo(int pageSize, int pageIndex, int outTotalPage, int outTotalCount) {
+		this.pageSize = pageSize;
+		this.pageIndex = pageIndex;
+		this.outTotalPage = outTotalPage;
+		this.outTotalCount = outTotalCount;
+
+	}
+
+	public HttpRetPageArr(int code, String msg, List<T> retObj) {
+		this.code = code;
+		this.msg = msg;
+		this.retArr = retObj;
+	}
+
+	public static <T> HttpRetPageArr<T> genResult(int code, String msg, List<T> retObj) {
+		HttpRetPageArr<T> result = new HttpRetPageArr<T>(code, msg, retObj);
+		return result;
+	}
+
+
+
+	public static <T> HttpRetPageArr<T> genResultPage(int code, String msg, TableDataInfo<T> tableDataInfo) {
+		HttpRetPageArr<T> result = new HttpRetPageArr<T>(code, msg, tableDataInfo.getRows());
+		result.outTotalCount = tableDataInfo.getTotal().intValue();
+		return result;
+	}
+
+	public static <T> HttpRetPageArr<T> success(String msg, List<T> data) {
+		return genResult(1, msg, data);
+	}
+
+	public static <T> HttpRetPageArr<T> success(String msg, TableDataInfo<T> tableDataInfo) {
+		return genResultPage(1, msg, tableDataInfo);
+	}
+
+	public static <T> HttpRetPageArr<T> success(String msg) {
+		return genResult(1, msg, null);
+	}
+
+	public static <T> HttpRetPageArr<T> fail(String message) {
+		return genResult(2, message, null);
+	}
+
+	public static <T> HttpRetPageArr<T> fail(int code, String message) {
+		return genResult(code, message, null);
+	}
+
+	@Override
+	public String toString() {
+		return "HttpRetArr{" + "code=" + code + ", msg='" + msg + '\'' + ", retArr=" + retArr + '}';
+	}
+
+}