From d910a3e7ad5bc3a5e5443f506d05bbb9e83a4c8e Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期四, 31 十月 2024 17:14:33 +0800
Subject: [PATCH] 生成试卷时如果题目列表为空,则不反悔这个题型的数据
---
src/main/java/com/ycl/jxkg/base/Result.java | 61 +++++++++++++++++++++---------
1 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/src/main/java/com/ycl/jxkg/base/Result.java b/src/main/java/com/ycl/jxkg/base/Result.java
index 192c798..977d7fe 100644
--- a/src/main/java/com/ycl/jxkg/base/Result.java
+++ b/src/main/java/com/ycl/jxkg/base/Result.java
@@ -9,9 +9,9 @@
* @date 2021/5/25 10:45
*/
public class Result<T> extends HashMap<String, Object> {
- private int code;
- private String message;
- private T response;
+
+ public Result() {
+ }
/**
* Instantiates a new Rest response.
@@ -20,8 +20,8 @@
* @param message the message
*/
public Result(int code, String message) {
- this.code = code;
- this.message = message;
+ this.put("code", code);
+ this.put("message", message);
}
/**
@@ -31,10 +31,12 @@
* @param message the message
* @param response the response
*/
- public Result(int code, String message, T response) {
- this.code = code;
- this.message = message;
- this.response = response;
+ public static Result response(int code, String message, Object response) {
+ Result restResponse = new Result();
+ restResponse.put("code", code);
+ restResponse.put("message", message);
+ restResponse.put("data", response);
+ return restResponse;
}
/**
@@ -45,7 +47,10 @@
* @return the rest response
*/
public static Result fail(Integer code, String msg) {
- return new Result<>(code, msg);
+ Result restResponse = new Result();
+ restResponse.put("code", code);
+ restResponse.put("message", msg);
+ return restResponse;
}
/**
@@ -55,7 +60,10 @@
*/
public static Result ok() {
SystemCode systemCode = SystemCode.OK;
- return new Result<>(systemCode.getCode(), systemCode.getMessage());
+ Result restResponse = new Result();
+ restResponse.put("code", systemCode.getCode());
+ restResponse.put("message", systemCode.getMessage());
+ return restResponse;
}
/**
@@ -67,7 +75,24 @@
*/
public static <F> Result<F> ok(F response) {
SystemCode systemCode = SystemCode.OK;
- return new Result<>(systemCode.getCode(), systemCode.getMessage(), response);
+ Result restResponse = new Result();
+ restResponse.put("code", systemCode.getCode());
+ restResponse.put("message", systemCode.getMessage());
+ restResponse.put("data", response);
+ return restResponse;
+ }
+
+ /**
+ * Ok rest response.
+ *
+ * @return the rest response
+ */
+ public static Result ok(String msg) {
+ SystemCode systemCode = SystemCode.OK;
+ Result restResponse = new Result();
+ restResponse.put("code", systemCode.getCode());
+ restResponse.put("message", msg);
+ return restResponse;
}
/**
@@ -76,7 +101,7 @@
* @return the code
*/
public int getCode() {
- return code;
+ return (int) this.get("code");
}
/**
@@ -85,7 +110,7 @@
* @param code the code
*/
public void setCode(int code) {
- this.code = code;
+ this.put("code", code);
}
/**
@@ -94,7 +119,7 @@
* @return the message
*/
public String getMessage() {
- return message;
+ return (String) this.get("message");
}
/**
@@ -103,7 +128,7 @@
* @param message the message
*/
public void setMessage(String message) {
- this.message = message;
+ this.put("message", message);
}
/**
@@ -112,7 +137,7 @@
* @return the response
*/
public T getResponse() {
- return response;
+ return (T) this.get("data");
}
/**
@@ -121,7 +146,7 @@
* @param response the response
*/
public void setResponse(T response) {
- this.response = response;
+ this.put("data", response);
}
@Override
--
Gitblit v1.8.0