|
|
@@ -27,18 +27,16 @@ public class CommonResult<T> extends BaseResult implements Serializable {
|
|
|
|
|
|
private T data;
|
|
|
|
|
|
- public CommonResult(Code code, T data) {
|
|
|
- this.status = code.getStatus();
|
|
|
- this.msg = code.getMsg();
|
|
|
- this.success = code.getSuccess();
|
|
|
- this.data = data;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private static final long serialVersionUID = 3616484754899974346L;
|
|
|
|
|
|
+
|
|
|
public static CommonResult ok() {
|
|
|
- return ok("1", "执行成功");
|
|
|
+ return ok(Integer.toString(ResponseStatusEnum.SUCCESS.getStatus()), ResponseStatusEnum.SUCCESS.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> CommonResult<T> ok(T data) {
|
|
|
+ CommonResult<T> result = new CommonResult<T>(data);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
public static <T> CommonResult<T> ok(String code, String msg) {
|
|
|
@@ -46,17 +44,50 @@ public class CommonResult<T> extends BaseResult implements Serializable {
|
|
|
}
|
|
|
|
|
|
public static CommonResult fail() {
|
|
|
- return fail("-1", "执行失败");
|
|
|
+ return fail(Integer.toString(ResponseStatusEnum.FAILED.getStatus()), ResponseStatusEnum.FAILED.getMsg());
|
|
|
}
|
|
|
|
|
|
public static CommonResult fail(String code, String msg) {
|
|
|
return baseCreate(code, msg, false);
|
|
|
}
|
|
|
|
|
|
+ public CommonResult() {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用Code自定义返回信息
|
|
|
+ * 并把数据返回
|
|
|
+ */
|
|
|
+ public CommonResult(Code code, T data) {
|
|
|
+ this.status = code.getStatus();
|
|
|
+ this.msg = code.getMsg();
|
|
|
+ this.success = code.getSuccess();
|
|
|
+ this.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 成功的返回信息
|
|
|
+ */
|
|
|
+ public CommonResult(T data) {
|
|
|
+ this.setCode(Integer.toString(ResponseStatusEnum.SUCCESS.status()));
|
|
|
+ this.setMessage(ResponseStatusEnum.SUCCESS.msg());
|
|
|
+ this.setSuccess(ResponseStatusEnum.SUCCESS.success());
|
|
|
+ this.setData(data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- public CommonResult() {
|
|
|
+ /**
|
|
|
+ * 自定义错误返回信息
|
|
|
+ * @param EnumCode 枚举错误信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public CommonResult(ResponseStatusEnum EnumCode) {
|
|
|
+ this.setCode(Integer.toString(EnumCode.status()));
|
|
|
+ this.setMessage(EnumCode.msg());
|
|
|
+ this.setSuccess(EnumCode.success());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private static <T> CommonResult<T> baseCreate(String code, String msg, boolean success) {
|
|
|
CommonResult result = new CommonResult();
|
|
|
result.setCode(code);
|
|
|
@@ -65,13 +96,6 @@ public class CommonResult<T> extends BaseResult implements Serializable {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public CommonResult(T data) {
|
|
|
- this.setCode(Integer.toString(ResponseStatusEnum.SUCCESS.status()));
|
|
|
- this.setMessage(ResponseStatusEnum.SUCCESS.msg());
|
|
|
- this.setSuccess(ResponseStatusEnum.SUCCESS.success());
|
|
|
- this.setData(data);
|
|
|
- }
|
|
|
-
|
|
|
public static CommonResult resultValue(ResponseStatusEnum responseStatus) {
|
|
|
return new CommonResult(responseStatus);
|
|
|
}
|
|
|
@@ -86,17 +110,10 @@ public class CommonResult<T> extends BaseResult implements Serializable {
|
|
|
return new CommonResult(ResponseStatusEnum.FAILED, map);
|
|
|
}
|
|
|
|
|
|
- public CommonResult(ResponseStatusEnum responseStatus, T data) {
|
|
|
- this.setCode(Integer.toString(responseStatus.status()));
|
|
|
- this.setMessage(responseStatus.msg());
|
|
|
- this.setSuccess(responseStatus.success());
|
|
|
- this.setData(data);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 错误返回,直接返回错误的消息
|
|
|
*
|
|
|
- * @param msg
|
|
|
+ * @param msg 提示信息
|
|
|
* @return
|
|
|
*/
|
|
|
public static CommonResult errorMsg(String msg) {
|