标签:spec 记录 demo cut poi stc return amp tco
@Aspect
@Component
public class LogAspect {
private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
@Pointcut("execution(public * com.example.demo.controller..*.*(..))") //切点
public void webLog() {
}
/**
*
* @param joinPoint
*/
@Before("webLog()") //切点之前执行
public void doBefore(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
log.info("请求的地址" + String.valueOf(request.getRequestURL()));
log.info("请求的IP" + String.valueOf(request.getRemoteAddr()));
}
@AfterReturning(returning = "ret", pointcut = "webLog()") //切点后返回值
public void doAfterReturning(Object ret) {
log.info(ret.toString());
}
}
标签:spec 记录 demo cut poi stc return amp tco
原文地址:https://www.cnblogs.com/cheng-11/p/10690225.html