接口处理时间打印
作者:互联网
public class RequestTimeInterceptor implements HandlerInterceptor { private static final Logger log = LoggerFactory.getLogger(RequestTimeInterceptor.class); @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { long startTime = System.currentTimeMillis(); request.setAttribute("startTime", startTime); return true; } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { long startTime = (Long)request.getAttribute("startTime"); request.removeAttribute("startTime"); long executeTime = System.currentTimeMillis() - startTime; log.info("接口:{},处理类:{},处理耗时:{}ms",request.getRequestURI(), handler, executeTime); } }
标签:处理,打印,request,HttpServletResponse,long,handler,接口,startTime,public 来源: https://www.cnblogs.com/pijunqi/p/15787036.html