作者 RuoYi

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

@@ -127,7 +127,7 @@ public class AjaxResult extends HashMap<String, Object> @@ -127,7 +127,7 @@ public class AjaxResult extends HashMap<String, Object>
127 /** 127 /**
128 * 返回错误消息 128 * 返回错误消息
129 * 129 *
130 - * @return 130 + * @return 错误消息
131 */ 131 */
132 public static AjaxResult error() 132 public static AjaxResult error()
133 { 133 {
@@ -138,7 +138,7 @@ public class AjaxResult extends HashMap<String, Object> @@ -138,7 +138,7 @@ public class AjaxResult extends HashMap<String, Object>
138 * 返回错误消息 138 * 返回错误消息
139 * 139 *
140 * @param msg 返回内容 140 * @param msg 返回内容
141 - * @return 警告消息 141 + * @return 错误消息
142 */ 142 */
143 public static AjaxResult error(String msg) 143 public static AjaxResult error(String msg)
144 { 144 {
@@ -150,7 +150,7 @@ public class AjaxResult extends HashMap<String, Object> @@ -150,7 +150,7 @@ public class AjaxResult extends HashMap<String, Object>
150 * 150 *
151 * @param msg 返回内容 151 * @param msg 返回内容
152 * @param data 数据对象 152 * @param data 数据对象
153 - * @return 警告消息 153 + * @return 错误消息
154 */ 154 */
155 public static AjaxResult error(String msg, Object data) 155 public static AjaxResult error(String msg, Object data)
156 { 156 {
@@ -162,7 +162,7 @@ public class AjaxResult extends HashMap<String, Object> @@ -162,7 +162,7 @@ public class AjaxResult extends HashMap<String, Object>
162 * 162 *
163 * @param code 状态码 163 * @param code 状态码
164 * @param msg 返回内容 164 * @param msg 返回内容
165 - * @return 警告消息 165 + * @return 错误消息
166 */ 166 */
167 public static AjaxResult error(int code, String msg) 167 public static AjaxResult error(int code, String msg)
168 { 168 {
@@ -4,6 +4,10 @@ import java.io.IOException; @@ -4,6 +4,10 @@ import java.io.IOException;
4 import java.io.UnsupportedEncodingException; 4 import java.io.UnsupportedEncodingException;
5 import java.net.URLDecoder; 5 import java.net.URLDecoder;
6 import java.net.URLEncoder; 6 import java.net.URLEncoder;
  7 +import java.util.Collections;
  8 +import java.util.HashMap;
  9 +import java.util.Map;
  10 +import javax.servlet.ServletRequest;
7 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse; 12 import javax.servlet.http.HttpServletResponse;
9 import javax.servlet.http.HttpSession; 13 import javax.servlet.http.HttpSession;
@@ -69,6 +73,34 @@ public class ServletUtils @@ -69,6 +73,34 @@ public class ServletUtils
69 } 73 }
70 74
71 /** 75 /**
  76 + * 获得所有请求参数
  77 + *
  78 + * @param request 请求对象{@link ServletRequest}
  79 + * @return Map
  80 + */
  81 + public static Map<String, String[]> getParams(ServletRequest request)
  82 + {
  83 + final Map<String, String[]> map = request.getParameterMap();
  84 + return Collections.unmodifiableMap(map);
  85 + }
  86 +
  87 + /**
  88 + * 获得所有请求参数
  89 + *
  90 + * @param request 请求对象{@link ServletRequest}
  91 + * @return Map
  92 + */
  93 + public static Map<String, String> getParamMap(ServletRequest request)
  94 + {
  95 + Map<String, String> params = new HashMap<>();
  96 + for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
  97 + {
  98 + params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
  99 + }
  100 + return params;
  101 + }
  102 +
  103 + /**
72 * 获取request 104 * 获取request
73 */ 105 */
74 public static HttpServletRequest getRequest() 106 public static HttpServletRequest getRequest()
@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; @@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory;
13 import org.springframework.stereotype.Component; 13 import org.springframework.stereotype.Component;
14 import org.springframework.validation.BindingResult; 14 import org.springframework.validation.BindingResult;
15 import org.springframework.web.multipart.MultipartFile; 15 import org.springframework.web.multipart.MultipartFile;
16 -import org.springframework.web.servlet.HandlerMapping;  
17 import com.alibaba.fastjson2.JSON; 16 import com.alibaba.fastjson2.JSON;
18 import com.ruoyi.common.annotation.Log; 17 import com.ruoyi.common.annotation.Log;
19 import com.ruoyi.common.core.domain.model.LoginUser; 18 import com.ruoyi.common.core.domain.model.LoginUser;
@@ -103,7 +102,6 @@ public class LogAspect @@ -103,7 +102,6 @@ public class LogAspect
103 catch (Exception exp) 102 catch (Exception exp)
104 { 103 {
105 // 记录本地异常日志 104 // 记录本地异常日志
106 - log.error("==前置通知异常==");  
107 log.error("异常信息:{}", exp.getMessage()); 105 log.error("异常信息:{}", exp.getMessage());
108 exp.printStackTrace(); 106 exp.printStackTrace();
109 } 107 }
@@ -153,8 +151,8 @@ public class LogAspect @@ -153,8 +151,8 @@ public class LogAspect
153 } 151 }
154 else 152 else
155 { 153 {
156 - Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);  
157 - operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); 154 + Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
  155 + operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000));
158 } 156 }
159 } 157 }
160 158