Browse Source

通用Controller添加响应返回消息

RuoYi 5 years ago
parent
commit
0f733b89dc

+ 9 - 5
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/text/Convert.java

@@ -797,16 +797,20 @@ public class Convert
797 797
         }
798 798
         else if (obj instanceof byte[] || obj instanceof Byte[])
799 799
         {
800
-            if (obj instanceof byte[]){
800
+            if (obj instanceof byte[])
801
+            {
801 802
                 return str((byte[]) obj, charset);
802
-            } else {
803
-                Byte[] bytes = (Byte[])obj;
803
+            }
804
+            else
805
+            {
806
+                Byte[] bytes = (Byte[]) obj;
804 807
                 int length = bytes.length;
805 808
                 byte[] dest = new byte[length];
806
-                for (int i = 0; i < length; i++) {
809
+                for (int i = 0; i < length; i++)
810
+                {
807 811
                     dest[i] = bytes[i];
808 812
                 }
809
-            return str (dest,charset);
813
+                return str(dest, charset);
810 814
             }
811 815
         }
812 816
         else if (obj instanceof ByteBuffer)

+ 43 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/controller/BaseController.java

@@ -83,4 +83,47 @@ public class BaseController
83 83
     {
84 84
         return rows > 0 ? AjaxResult.success() : AjaxResult.error();
85 85
     }
86
+
87
+    /**
88
+     * 响应返回结果
89
+     * 
90
+     * @param result 结果
91
+     * @return 操作结果
92
+     */
93
+    protected AjaxResult toAjax(boolean result)
94
+    {
95
+        return result ? success() : error();
96
+    }
97
+
98
+    /**
99
+     * 返回成功
100
+     */
101
+    public AjaxResult success()
102
+    {
103
+        return AjaxResult.success();
104
+    }
105
+
106
+    /**
107
+     * 返回失败消息
108
+     */
109
+    public AjaxResult error()
110
+    {
111
+        return AjaxResult.error();
112
+    }
113
+
114
+    /**
115
+     * 返回成功消息
116
+     */
117
+    public AjaxResult success(String message)
118
+    {
119
+        return AjaxResult.success(message);
120
+    }
121
+
122
+    /**
123
+     * 返回失败消息
124
+     */
125
+    public AjaxResult error(String message)
126
+    {
127
+        return AjaxResult.error(message);
128
+    }
86 129
 }