Skip to content

2.1.4 日志管理---没有记录查询接口参数 #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacy000111 opened this issue Apr 8, 2020 · 1 comment
Closed

2.1.4 日志管理---没有记录查询接口参数 #1070

jacy000111 opened this issue Apr 8, 2020 · 1 comment

Comments

@jacy000111
Copy link

版本号:

2.1.4

问题描述:

日志管理,没有记录查询接口参数

截图&代码:

AutoLogAspect.java

	//请求的参数
	Object[] args = joinPoint.getArgs();
	try{
		String params = JSONObject.toJSONString(args);
		sysLog.setRequestParam(params);
	}catch (Exception e){

	}

---------------我是这么处理的----------------------
//请求的参数
Object[] args = joinPoint.getArgs();
try{
String params = this.getReqestParams(request,joinPoint);
sysLog.setRequestParam(params);
}catch (Exception e){

	}


private String getReqestParams(HttpServletRequest request, JoinPoint joinPoint){
    String httpMethod = request.getMethod();
    String params = "";
    if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) || "PATCH".equals(httpMethod)) {
        Object[] paramsArray = joinPoint.getArgs();
        params = argsArrayToString(paramsArray);
    } else {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        // 请求的方法参数值
        Object[] args = joinPoint.getArgs();
        // 请求的方法参数名称
        LocalVariableTableParameterNameDiscoverer u = new 
        LocalVariableTableParameterNameDiscoverer();
        String[] paramNames = u.getParameterNames(method);
        if (args != null && paramNames != null) {
            for (int i = 0; i < args.length; i++) {
                params += "  " + paramNames[i] + ": " + args[i];
            }
        }
    }
    return params;
}

友情提示: 未按格式要求发帖,会直接删掉。

@zhangdaiscott
Copy link
Member

非常感谢,已收录

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants