瀏覽代碼

修复Log注解GET请求记录不到参数问题

RuoYi 3 年之前
父節點
當前提交
a8be0ccb35

+ 31 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java

@@ -4,8 +4,11 @@ import java.io.IOException;
4 4
 import java.io.UnsupportedEncodingException;
5 5
 import java.net.URLDecoder;
6 6
 import java.net.URLEncoder;
7
+import java.util.Collections;
7 8
 import java.util.Enumeration;
9
+import java.util.HashMap;
8 10
 import java.util.Map;
11
+import javax.servlet.ServletRequest;
9 12
 import javax.servlet.http.HttpServletRequest;
10 13
 import javax.servlet.http.HttpServletResponse;
11 14
 import javax.servlet.http.HttpSession;
@@ -80,6 +83,34 @@ public class ServletUtils
80 83
     }
81 84
 
82 85
     /**
86
+     * 获得所有请求参数
87
+     *
88
+     * @param request 请求对象{@link ServletRequest}
89
+     * @return Map
90
+     */
91
+    public static Map<String, String[]> getParams(ServletRequest request)
92
+    {
93
+        final Map<String, String[]> map = request.getParameterMap();
94
+        return Collections.unmodifiableMap(map);
95
+    }
96
+
97
+    /**
98
+     * 获得所有请求参数
99
+     *
100
+     * @param request 请求对象{@link ServletRequest}
101
+     * @return Map
102
+     */
103
+    public static Map<String, String> getParamMap(ServletRequest request)
104
+    {
105
+        Map<String, String> params = new HashMap<>();
106
+        for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
107
+        {
108
+            params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
109
+        }
110
+        return params;
111
+    }
112
+
113
+    /**
83 114
      * 获取request
84 115
      */
85 116
     public static HttpServletRequest getRequest()

+ 4 - 4
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/AjaxResult.java

@@ -128,7 +128,7 @@ public class AjaxResult extends HashMap<String, Object>
128 128
     /**
129 129
      * 返回错误消息
130 130
      * 
131
-     * @return
131
+     * @return 错误消息
132 132
      */
133 133
     public static AjaxResult error()
134 134
     {
@@ -139,7 +139,7 @@ public class AjaxResult extends HashMap<String, Object>
139 139
      * 返回错误消息
140 140
      * 
141 141
      * @param msg 返回内容
142
-     * @return 警告消息
142
+     * @return 错误消息
143 143
      */
144 144
     public static AjaxResult error(String msg)
145 145
     {
@@ -151,7 +151,7 @@ public class AjaxResult extends HashMap<String, Object>
151 151
      * 
152 152
      * @param msg 返回内容
153 153
      * @param data 数据对象
154
-     * @return 警告消息
154
+     * @return 错误消息
155 155
      */
156 156
     public static AjaxResult error(String msg, Object data)
157 157
     {
@@ -163,7 +163,7 @@ public class AjaxResult extends HashMap<String, Object>
163 163
      * 
164 164
      * @param code 状态码
165 165
      * @param msg 返回内容
166
-     * @return 警告消息
166
+     * @return 错误消息
167 167
      */
168 168
     public static AjaxResult error(int code, String msg)
169 169
     {

+ 5 - 1
ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java

@@ -102,7 +102,6 @@ public class LogAspect
102 102
         catch (Exception exp)
103 103
         {
104 104
             // 记录本地异常日志
105
-            log.error("==前置通知异常==");
106 105
             log.error("异常信息:{}", exp.getMessage());
107 106
             exp.printStackTrace();
108 107
         }
@@ -150,6 +149,11 @@ public class LogAspect
150 149
             String params = argsArrayToString(joinPoint.getArgs());
151 150
             operLog.setOperParam(StringUtils.substring(params, 0, 2000));
152 151
         }
152
+        else
153
+        {
154
+            Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
155
+            operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000));
156
+        }
153 157
     }
154 158
 
155 159
     /**

+ 2 - 1
ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/XssFilter.java

@@ -43,7 +43,8 @@ public class XssFilter implements GlobalFilter, Ordered
43 43
     {
44 44
         ServerHttpRequest request = exchange.getRequest();
45 45
         // xss开关未开启 或 通过nacos关闭,不过滤
46
-        if(!xss.getEnabled()){
46
+        if (!xss.getEnabled())
47
+        {
47 48
             return chain.filter(exchange);
48 49
         }
49 50
         // GET DELETE 不过滤

+ 1 - 5
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -71,11 +71,7 @@ public class SysDeptServiceImpl implements ISysDeptService
71 71
     public List<SysDept> buildDeptTree(List<SysDept> depts)
72 72
     {
73 73
         List<SysDept> returnList = new ArrayList<SysDept>();
74
-        List<Long> tempList = new ArrayList<Long>();
75
-        for (SysDept dept : depts)
76
-        {
77
-            tempList.add(dept.getDeptId());
78
-        }
74
+        List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
79 75
         for (SysDept dept : depts)
80 76
         {
81 77
             // 如果是顶级节点, 遍历该父节点的所有子节点

+ 1 - 5
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java

@@ -223,11 +223,7 @@ public class SysMenuServiceImpl implements ISysMenuService
223 223
     public List<SysMenu> buildMenuTree(List<SysMenu> menus)
224 224
     {
225 225
         List<SysMenu> returnList = new ArrayList<SysMenu>();
226
-        List<Long> tempList = new ArrayList<Long>();
227
-        for (SysMenu dept : menus)
228
-        {
229
-            tempList.add(dept.getMenuId());
230
-        }
226
+        List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
231 227
         for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();)
232 228
         {
233 229
             SysMenu menu = (SysMenu) iterator.next();