From 1bb6342bcbcd02ecdb02476413c5f93c09bc15ff Mon Sep 17 00:00:00 2001 From: RuoYi Date: Tue, 22 Nov 2022 10:41:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DLog=E6=B3=A8=E8=A7=A3GET?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=AE=B0=E5=BD=95=E4=B8=8D=E5=88=B0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/domain/AjaxResult.java | 8 ++--- .../com/ruoyi/common/utils/ServletUtils.java | 32 +++++++++++++++++++ .../ruoyi/framework/aspectj/LogAspect.java | 6 ++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java index ad9d96b..790753d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java @@ -127,7 +127,7 @@ public class AjaxResult extends HashMap /** * 返回错误消息 * - * @return + * @return 错误消息 */ public static AjaxResult error() { @@ -138,7 +138,7 @@ public class AjaxResult extends HashMap * 返回错误消息 * * @param msg 返回内容 - * @return 警告消息 + * @return 错误消息 */ public static AjaxResult error(String msg) { @@ -150,7 +150,7 @@ public class AjaxResult extends HashMap * * @param msg 返回内容 * @param data 数据对象 - * @return 警告消息 + * @return 错误消息 */ public static AjaxResult error(String msg, Object data) { @@ -162,7 +162,7 @@ public class AjaxResult extends HashMap * * @param code 状态码 * @param msg 返回内容 - * @return 警告消息 + * @return 错误消息 */ public static AjaxResult error(int code, String msg) { diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java index 1cbf72f..292b8da 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java @@ -4,6 +4,10 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -68,6 +72,34 @@ public class ServletUtils return Convert.toBool(getRequest().getParameter(name), defaultValue); } + /** + * 获得所有请求参数 + * + * @param request 请求对象{@link ServletRequest} + * @return Map + */ + public static Map getParams(ServletRequest request) + { + final Map map = request.getParameterMap(); + return Collections.unmodifiableMap(map); + } + + /** + * 获得所有请求参数 + * + * @param request 请求对象{@link ServletRequest} + * @return Map + */ + public static Map getParamMap(ServletRequest request) + { + Map params = new HashMap<>(); + for (Map.Entry entry : getParams(request).entrySet()) + { + params.put(entry.getKey(), StringUtils.join(entry.getValue(), ",")); + } + return params; + } + /** * 获取request */ diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java index 804b4fe..323f0b7 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java @@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import org.springframework.validation.BindingResult; import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.HandlerMapping; import com.alibaba.fastjson2.JSON; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.domain.model.LoginUser; @@ -103,7 +102,6 @@ public class LogAspect catch (Exception exp) { // 记录本地异常日志 - log.error("==前置通知异常=="); log.error("异常信息:{}", exp.getMessage()); exp.printStackTrace(); } @@ -153,8 +151,8 @@ public class LogAspect } else { - Map paramsMap = (Map) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); - operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); + Map paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); + operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000)); } }