@Before("execution(* com.lentra.dms.server.interceptors..*.pre*(..))")
public void allInterceptors(JoinPoint joinPoint)
{
StopWatch stopWatch = new StopWatch();
stopWatch.start();
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
request.setAttribute("stopwatch",stopWatch);
}
@Around("controller() || restController() ")
public Object saveLogAroundControllers(ProceedingJoinPoint pjp) throws Throwable {
StopWatch stopWatch = null;
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
if(request.getAttribute("stopwatch")!=null) {
stopWatch = (StopWatch) request.getAttribute("stopwatch");
}
ApiLoggerDto dto = new ApiLoggerDto();
1. loggerServiceImpl.log(dto);
apiResponse = pjp.proceed();
for(int i=0;i<100;i++)
{
logger.debug("asd");
}
if(stopWatch != null && stopWatch.isRunning()) {
stopWatch.stop();
}
**dto.setResponseTime(stopWatch.getLastTaskTimeMillis());**
loggerServiceImpl.log(dto);
} 秒表计时有问题。在第一种方法中,我在第一种方法中创建了一个秒表实例。在第1行之前,我节省了时间,即执行for循环后95毫秒,而在第2行中保存了95毫秒。
在第1行和第2行中保存了相同的时间。
请建议我更改。