1. 程式人生 > >@ControllerAdvice,ResponseBodyAdvice記錄日誌資訊

@ControllerAdvice,ResponseBodyAdvice記錄日誌資訊

我在專案中的用到@ControllerAdvice,ResponseBodyAdvice

beforeBodyWrite方法中內容大概如下:

可以在返回的body中加入其他資訊

ResponseResult result =(ResponseResult)body;

result.setRequestId(AppContextt.getResquestThreadId());

向日志表中加入資訊

UserLogDTO dto =new UserLogDTO();

dto.setUrl(request.getURI().getPath());

dto.setParams(IOUtIls.toString(request.getBody()));

dto.setResult(JSON.toJSONString(body));

commService.insertLog(dto);

return body;