打印示例
依赖
org.springframework.boot spring-boot-starter-aop com.google.code.gson gson 2.8.5
package com.dp.file.config;
import com.google.gson.Gson;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
@Aspect
@Component
public class FileLogAspect {
private final static Logger logger = LoggerFactory.getLogger(FileLogAspect.class);
@Pointcut("execution(public * com.dp.file.controller..*.*(..))")
public void fileLog() {
}
@Before("fileLog()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
logger.info("{} {} {} {}", request.getMethod(), request.getRequestURL().toString(), new Gson().toJson(joinPoint.getArgs()), request.getRemoteAddr());
}
@Around("fileLog()")
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
Object result = proceedingJoinPoint.proceed();
logger.info("Response Args : {}", new Gson().toJson(result));
return result;
}
}
问题:
文件下载接口报错
还不知道咋解决,看见一篇讲了为啥不用阿里的FASTJSON 而是用谷歌的 Gson的。
他说FASTJSON在上传文件接口那里出错,但是Gson在下载文件接口出错啊淦!
https://blog.csdn.net/qq_23000805/article/details/120509829



