From edf8cfc4ca8793301344e767952e2eb608cb7880 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期二, 29 十二月 2020 15:13:14 +0800
Subject: [PATCH] 提交时间

---
 java110-bean/src/main/java/com/java110/vo/ResultVo.java |  106 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 99 insertions(+), 7 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 6839dab..f2ba756 100644
--- a/java110-bean/src/main/java/com/java110/vo/ResultVo.java
+++ b/java110-bean/src/main/java/com/java110/vo/ResultVo.java
@@ -1,6 +1,8 @@
 package com.java110.vo;
 
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 
@@ -18,13 +20,14 @@
 
     public static final int CODE_ERROR = 404;// 鏈煡寮傚父
 
-    public static final int CODE_OK = 200; // 鎴愬姛
+    public static final int CODE_OK = 0; // 鎴愬姛
 
     public static final int CODE_MACHINE_OK = 0; // 鎴愬姛
 
     public static final int CODE_MACHINE_ERROR = -1; // 鏈煡寮傚父
 
     public static final int CODE_UNAUTHORIZED = 401; //璁よ瘉澶辫触
+    public static final int CODE_WECHAT_UNAUTHORIZED = 1401; //璁よ瘉澶辫触
 
     public static final int ORDER_ERROR = 500; //璁㈠崟璋冨害寮傚父
 
@@ -34,6 +37,9 @@
     public static final String MSG_OK = "鎴愬姛"; // 鎴愬姛
 
     public static final String MSG_UNAUTHORIZED = "璁よ瘉澶辫触"; //璁よ瘉澶辫触
+
+    public static final int DEFAULT_RECORD = 1;
+    public static final int DEFAULT_TOTAL = 1;
 
     // 鍒嗛〉椤垫暟
     private int page;
@@ -149,14 +155,59 @@
 
     @Override
     public String toString() {
-        return JSONObject.toJSONString(this);
+        return JSONObject.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
+    }
+
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param data 鏁版嵁瀵硅薄
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(Object data) {
+        ResultVo resultVo = new ResultVo(DEFAULT_RECORD, DEFAULT_TOTAL, data);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
     }
 
     /**
      * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param resultVo 鏁版嵁瀵硅薄
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(ResultVo resultVo) {
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鎴愬姛閫氱敤鍥炲
+     * @return
+     */
+    public static ResponseEntity<String> success() {
+        ResultVo resultVo = new ResultVo(CODE_OK, MSG_OK);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        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;
+    }
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
      * @param records 椤垫暟
-     * @param total 鎬昏褰曟暟
-     * @param data 鏁版嵁瀵硅薄
+     * @param total   鎬昏褰曟暟
+     * @param data    鏁版嵁瀵硅薄
      * @return
      */
     public static ResponseEntity<String> createResponseEntity(int records, int total, Object data) {
@@ -166,14 +217,55 @@
     }
 
     /**
+     * 椤甸潰璺宠浆
+     *
+     * @param url
+     * @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);
+        return responseEntity;
+    }
+
+    /**
      * 鍒涘缓ResponseEntity瀵硅薄
-     * @param records 椤垫暟
-     * @param total 鎬昏褰曟暟
+     *
      * @param code 鐘舵�佸槢
-     * @param msg 杩斿洖淇℃伅
+     * @param msg  杩斿洖淇℃伅
      * @param data 鏁版嵁瀵硅薄
      * @return
      */
+    public static ResponseEntity<String> createResponseEntity(int code, String msg, Object data) {
+        ResultVo resultVo = new ResultVo(code, msg, data);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param code 鐘舵�佸槢
+     * @param msg  杩斿洖淇℃伅
+     * @return
+     */
+    public static ResponseEntity<String> createResponseEntity(int code, String msg) {
+        ResultVo resultVo = new ResultVo(code, msg);
+        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
+        return responseEntity;
+    }
+
+    /**
+     * 鍒涘缓ResponseEntity瀵硅薄
+     *
+     * @param records 椤垫暟
+     * @param total   鎬昏褰曟暟
+     * @param code    鐘舵�佸槢
+     * @param msg     杩斿洖淇℃伅
+     * @param data    鏁版嵁瀵硅薄
+     * @return
+     */
     public static ResponseEntity<String> createResponseEntity(int records, int total, int code, String msg, Object data) {
         ResultVo resultVo = new ResultVo(records, total, code, msg, data);
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

--
Gitblit v1.8.0