From c2614ad5c7d1e27fae68e52cd058af363464cdb4 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期六, 21 五月 2022 23:16:38 +0800
Subject: [PATCH] 优化代码
---
java110-bean/src/main/java/com/java110/vo/ResultVo.java | 43 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/java110-bean/src/main/java/com/java110/vo/ResultVo.java b/java110-bean/src/main/java/com/java110/vo/ResultVo.java
index ee7ea09..b47fdb7 100755
--- a/java110-bean/src/main/java/com/java110/vo/ResultVo.java
+++ b/java110-bean/src/main/java/com/java110/vo/ResultVo.java
@@ -2,6 +2,8 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
+import org.slf4j.Logger;
+
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -17,6 +19,8 @@
* add by wuxw 2020/5/28
**/
public class ResultVo implements Serializable {
+
+
public static final int CODE_ERROR = 404;// 鏈煡寮傚父
@@ -42,6 +46,10 @@
public static final int DEFAULT_RECORD = 1;
public static final int DEFAULT_TOTAL = 1;
+ public static final int CODE_WAIT_PAY = 41;// 鏀粯鏈畬鎴�
+
+ public static final String EMPTY_ARRAY = "[]";
+
// 鍒嗛〉椤垫暟
private int page;
// 琛屾暟
@@ -51,7 +59,7 @@
private int records;
// 鎬昏褰曟暟
- private int total;
+ private long total;
//鐘舵��
private int code;
@@ -83,6 +91,14 @@
}
public ResultVo(int records, int total, Object data) {
+ this.code = CODE_OK;
+ this.msg = MSG_OK;
+ this.records = records;
+ this.total = total;
+ this.data = data;
+ }
+
+ public ResultVo(int records, long total, Object data) {
this.code = CODE_OK;
this.msg = MSG_OK;
this.records = records;
@@ -147,7 +163,7 @@
this.records = records;
}
- public int getTotal() {
+ public long getTotal() {
return total;
}
@@ -240,8 +256,30 @@
*
* @return
*/
+ public static ResponseEntity<String> error(String msg,HttpStatus status) {
+ ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
+ ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), status);
+ return responseEntity;
+ }
+
+ /**
+ * 鎴愬姛閫氱敤鍥炲
+ *
+ * @return
+ */
public static ResponseEntity<String> error(String msg) {
ResultVo resultVo = new ResultVo(CODE_ERROR, msg);
+ ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+ return responseEntity;
+ }
+
+ /**
+ * 鎴愬姛閫氱敤鍥炲
+ *
+ * @return
+ */
+ public static ResponseEntity<String> error(String msg,Object data) {
+ ResultVo resultVo = new ResultVo(CODE_ERROR, msg,data);
ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
return responseEntity;
}
@@ -282,6 +320,7 @@
* @return
*/
public static ResponseEntity<String> redirectPage(String url) {
+
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.LOCATION, url);
ResponseEntity<String> responseEntity = new ResponseEntity<String>("", headers, HttpStatus.FOUND);
--
Gitblit v1.8.0